Skip to main content

powerpoint_ooxml/
error.rs

1//! Error type for `powerpoint-ooxml`.
2
3use thiserror::Error;
4
5/// Errors that can occur while reading or writing a `.pptx` presentation.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// An error occurred at the OPC package level (ZIP container, parts, relationships).
9    #[error("OPC package error: {0}")]
10    Opc(#[from] opc::Error),
11
12    /// An error occurred while reading or writing XML.
13    #[error("XML error: {0}")]
14    Xml(#[from] xml_core::Error),
15
16    /// An error occurred while reading or writing a shape's DrawingML content
17    /// (fill/line/text/geometry).
18    #[error("drawing error: {0}")]
19    Drawing(#[from] drawing::Error),
20
21    /// An error occurred while reading or writing an embedded chart's content.
22    #[error("chart error: {0}")]
23    Chart(#[from] chart::Error),
24
25    /// A part is not valid UTF-8.
26    #[error("part '{0}' is not valid UTF-8: {1}")]
27    InvalidUtf8(String, std::str::Utf8Error),
28
29    /// The package has no relationship of type `../relationships/officeDocument`, so the main
30    /// `ppt/presentation.xml` part could not be located.
31    #[error("the package has no main presentation part (missing officeDocument relationship)")]
32    MissingMainPresentation,
33
34    /// `ppt/presentation.xml`'s `<p:sldIdLst>` referenced a relationship id (`r:id`) that has no
35    /// matching entry in `ppt/_rels/presentation.xml.rels`.
36    #[error("slide relationship '{0}' is not declared in ppt/_rels/presentation.xml.rels")]
37    MissingSlideRelationship(String),
38
39    /// A `<p:sldId>`'s relationship resolved to a part name that isn't actually present in the
40    /// package.
41    #[error("slide part '{0}' is missing from the package")]
42    MissingSlidePart(String),
43
44    /// A `<p:pic>`'s `<a:blip r:embed="..">` referenced a relationship id that has no matching
45    /// entry in the slide's own `.rels` part.
46    #[error("image relationship '{0}' is not declared in the slide's own .rels part")]
47    MissingImageRelationship(String),
48
49    /// An image relationship resolved to a part name that isn't actually present in the package.
50    #[error("image part '{0}' is missing from the package")]
51    MissingImagePart(String),
52
53    /// An image part's name doesn't carry a recognized extension
54    /// (`.png`/`.jpeg`/`.jpg`/`.gif`/`.bmp`).
55    #[error("image part '{0}' has an unsupported or unrecognized format")]
56    UnsupportedImageFormat(String),
57
58    /// A `<c:chart r:id="..">` referenced a relationship id that has no matching entry in the
59    /// slide's own `.rels` part.
60    #[error("chart relationship '{0}' is not declared in the slide's own .rels part")]
61    MissingChartRelationship(String),
62
63    /// A chart relationship resolved to a part name that isn't actually present in the package.
64    #[error("chart part '{0}' is missing from the package")]
65    MissingChartPart(String),
66
67    /// A slide's own `notesSlide` relationship resolved to a part name that isn't actually present
68    /// in the package.
69    #[error("notes slide part '{0}' is missing from the package")]
70    MissingNotesPart(String),
71
72    /// A `<p:pic>`'s `<a:videoFile>`/`<a:audioFile r:link=".">` referenced a relationship id that
73    /// has no matching entry in the slide's own `.rels` part.
74    #[error("media relationship '{0}' is not declared in the slide's own .rels part")]
75    MissingMediaRelationship(String),
76
77    /// A media relationship resolved to a part name that isn't actually present in the package.
78    #[error("media part '{0}' is missing from the package")]
79    MissingMediaPart(String),
80
81    /// A media part's name doesn't carry a recognized extension
82    /// (`.mp4`/`.wmv`/`.avi`/`.mp3`/`.wav`).
83    #[error("media part '{0}' has an unsupported or unrecognized format")]
84    UnsupportedMediaFormat(String),
85
86    /// A table style id ([`SlideTable::style_id`](crate::model::SlideTable::style_id) or
87    /// [`SlideTableStyle::id`](crate::model::SlideTableStyle)) is not a valid `ST_Guid`. ECMA-376
88    /// requires both `<a:tblStyle styleId="..">` and `<a:tableStyleId>` to hold a GUID in
89    /// `{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}` form (uppercase hex) — anything else serializes to
90    /// schema-invalid XML that PowerPoint reports as a damaged file needing repair, with no error
91    /// at write time to explain why. Caught here instead, before that XML is ever written.
92    #[error(
93        "table style id '{0}' is not a valid GUID — OOXML requires the form \
94         `{{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}}` (uppercase hex); a non-GUID id \
95         writes schema-invalid XML that PowerPoint will refuse to open without repairing"
96    )]
97    InvalidTableStyleId(String),
98}
99
100/// A [`Result`](std::result::Result) alias using [`Error`] as the error type.
101pub type Result<T> = std::result::Result<T, Error>;