1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Error type for `word-ooxml`.
use thiserror::Error;
/// Errors that can occur while reading or writing a `.docx` document.
#[derive(Debug, Error)]
pub enum Error {
/// An error occurred at the OPC package level (ZIP container, parts,
/// relationships).
#[error("OPC package error: {0}")]
Opc(#[from] opc::Error),
/// An error occurred while reading or writing XML.
#[error("XML error: {0}")]
Xml(#[from] xml_core::Error),
/// The package has no relationship of type
/// `.../relationships/officeDocument`, so the main document part could
/// not be located.
#[error("the package has no main document part (missing officeDocument relationship)")]
MissingMainDocument,
/// The main document part is not valid UTF-8.
#[error("document.xml is not valid UTF-8: {0}")]
InvalidUtf8(#[from] std::str::Utf8Error),
/// A `<w:drawing>` referenced a relationship id (`r:embed`) that has
/// no matching entry in `word/_rels/document.xml.rels`.
#[error("image relationship '{0}' is not declared in word/_rels/document.xml.rels")]
MissingImageRelationship(String),
/// A `<w:drawing>`'s relationship resolved to a part name that isn't
/// actually present in the package.
#[error("image part '{0}' is missing from the package")]
MissingImagePart(String),
/// An image part's extension isn't one of the formats we support
/// reading back (see [`crate::ImageFormat`]).
#[error("unsupported image format for part '{0}'")]
UnsupportedImageFormat(String),
/// A `<w:headerReference>`/`<w:footerReference>` referenced a
/// relationship id (`r:id`) that has no matching entry in
/// `word/_rels/document.xml.rels`.
#[error("header/footer relationship '{0}' is not declared in word/_rels/document.xml.rels")]
MissingHeaderFooterRelationship(String),
/// A `<w:headerReference>`/`<w:footerReference>`'s relationship
/// resolved to a part name that isn't actually present in the package.
#[error("header/footer part '{0}' is missing from the package")]
MissingHeaderFooterPart(String),
/// `word/document.xml` declares a relationship to `word/styles.xml`,
/// but that part isn't actually present in the package.
#[error("styles part '{0}' is missing from the package")]
MissingStylesPart(String),
/// `word/document.xml` declares a relationship to `word/numbering.xml`,
/// but that part isn't actually present in the package.
#[error("numbering part '{0}' is missing from the package")]
MissingNumberingPart(String),
/// `word/document.xml` declares a relationship to `word/footnotes.xml`,
/// but that part isn't actually present in the package.
#[error("footnotes part '{0}' is missing from the package")]
MissingFootnotesPart(String),
/// `word/document.xml` declares a relationship to `word/endnotes.xml`,
/// but that part isn't actually present in the package.
#[error("endnotes part '{0}' is missing from the package")]
MissingEndnotesPart(String),
/// `word/document.xml` declares a relationship to `word/comments.xml`,
/// but that part isn't actually present in the package.
#[error("comments part '{0}' is missing from the package")]
MissingCommentsPart(String),
/// `word/document.xml` declares a relationship to
/// `word/theme/theme1.xml`, but that part isn't actually present in the
/// package.
#[error("theme part '{0}' is missing from the package")]
MissingThemePart(String),
/// An error occurred while reading or writing a shape's DrawingML
/// content (fill/line/text/image reference) inside an inline drawing.
#[error("drawing error: {0}")]
Drawing(#[from] drawing::Error),
/// An error occurred while reading or writing an embedded chart's
/// content.
#[error("chart error: {0}")]
Chart(#[from] chart::Error),
/// A `<w:drawing>` referenced a chart relationship id (`r:id` on
/// `<c:chart>`) that has no matching entry in the owning part's
/// `.rels`.
#[error("chart relationship '{0}' is not declared in the owning part's .rels")]
MissingChartRelationship(String),
/// A `<w:drawing>`'s chart relationship resolved to a part name that
/// isn't actually present in the package.
#[error("chart part '{0}' is missing from the package")]
MissingChartPart(String),
}
/// A [`Result`](std::result::Result) alias using [`Error`] as the error type.
pub type Result<T> = std::result::Result<T, Error>;