Skip to main content

xml_core/
error.rs

1//! Error type for `xml-core`.
2
3use thiserror::Error;
4
5/// Errors that can occur while reading or writing XML with `xml-core`.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// An I/O error occurred while reading or writing.
9    #[error("I/O error: {0}")]
10    Io(#[from] std::io::Error),
11
12    /// The underlying XML parser reported an error (malformed XML).
13    #[error("XML parsing error: {0}")]
14    Xml(#[from] quick_xml::Error),
15
16    /// Decoding the text content of an event failed (e.g. invalid encoding).
17    #[error("text decoding error: {0}")]
18    Decoding(#[from] quick_xml::encoding::EncodingError),
19
20    /// Un-escaping already-decoded text failed (e.g. an unknown or
21    /// malformed entity reference such as `&foo;`). Surfaced by
22    /// [`crate::decode_text`]/[`crate::decode_attribute_value`], which pair
23    /// `quick_xml`'s decoding with the matching un-escaping step — see
24    /// their doc comments for why both are needed.
25    #[error("XML unescaping error: {0}")]
26    Unescaping(#[from] quick_xml::escape::EscapeError),
27}
28
29/// A [`Result`](std::result::Result) alias using [`Error`] as the error type.
30pub type Result<T> = std::result::Result<T, Error>;