Skip to main content

excel_ooxml/
error.rs

1//! Error type for `excel-ooxml`.
2
3use thiserror::Error;
4
5/// Errors that can occur while reading or writing a `.xlsx` workbook.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// An error occurred at the OPC package level (ZIP container, parts,
9    /// relationships).
10    #[error("OPC package error: {0}")]
11    Opc(#[from] opc::Error),
12
13    /// An error occurred while reading or writing XML.
14    #[error("XML error: {0}")]
15    Xml(#[from] xml_core::Error),
16
17    /// An error occurred while reading or writing a shape's DrawingML
18    /// content (fill/line/text/image reference) inside a sheet's drawing.
19    #[error("drawing error: {0}")]
20    Drawing(#[from] drawing::Error),
21
22    /// An error occurred while reading or writing an embedded chart's
23    /// content.
24    #[error("chart error: {0}")]
25    Chart(#[from] chart::Error),
26
27    /// A sheet's drawing part (`xl/drawings/drawingN.xml`) is referenced by
28    /// the worksheet but missing from the package.
29    #[error("drawing part '{0}' is missing from the package")]
30    MissingDrawingPart(String),
31
32    /// A drawing anchor references an image or chart relationship id that
33    /// has no matching entry in the drawing part's own `.rels`.
34    #[error("drawing relationship '{0}' is not declared in the drawing part's .rels")]
35    MissingDrawingRelationship(String),
36
37    /// A drawing anchor's image/chart relationship resolved to a part name
38    /// that isn't actually present in the package.
39    #[error("part '{0}' referenced by a drawing is missing from the package")]
40    MissingDrawingReferencedPart(String),
41
42    /// The package has no relationship of type
43    /// `.../relationships/officeDocument`, so `xl/workbook.xml` could not
44    /// be located.
45    #[error("the package has no main workbook part (missing officeDocument relationship)")]
46    MissingWorkbook,
47
48    /// A part's content is not valid UTF-8.
49    #[error("'{0}' is not valid UTF-8: {1}")]
50    InvalidUtf8(String, std::str::Utf8Error),
51
52    /// `xl/workbook.xml` declares a `<sheet>` whose relationship id
53    /// (`r:id`) has no matching entry in `xl/_rels/workbook.xml.rels`.
54    #[error("sheet relationship '{0}' is not declared in xl/_rels/workbook.xml.rels")]
55    MissingSheetRelationship(String),
56
57    /// A sheet's relationship resolved to a part name that isn't actually
58    /// present in the package.
59    #[error("worksheet part '{0}' is missing from the package")]
60    MissingWorksheetPart(String),
61}
62
63/// A [`Result`](std::result::Result) alias using [`Error`] as the error type.
64pub type Result<T> = std::result::Result<T, Error>;