word-ooxml 1.0.0

Reading and writing of the WordprocessingML format (.docx).
Documentation
//! 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>;