async_xml/
error.rs

1//! Module for the [`Error`](enum@Error) and [`Result`] types.
2
3use thiserror::Error;
4
5/// A [`Result`](std::result::Result) using [`Error`](enum@Error) as the error type
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// The error type for this crate
9#[derive(Debug, Error)]
10pub enum Error {
11    /// Failed to parse XML
12    #[error("Failed to parse XML: {0}")]
13    Xml(quick_xml::Error),
14    /// Start element doesn't match the expected element
15    #[error("Expected start element <{0}>, found <{1}>")]
16    WrongStart(String, String),
17    /// End element doesn't match the expected element
18    #[error("Expected end element </{0}>, found </{1}>")]
19    WrongEnd(String, String),
20    /// Start element missing
21    #[error("Missing start element")]
22    MissingStart,
23    /// Missing required attribute
24    #[error("Missing attribute {0}")]
25    MissingAttribute(String),
26    /// Missing required child element
27    #[error("Missing child <{0}>")]
28    MissingChild(String),
29    /// Missing required element text
30    #[error("Missing element text")]
31    MissingText,
32    /// Encountered multiple child elements with the given name when only one was expected
33    #[error("Found multiple child elements <{0}>, but only expected one")]
34    DoubleChild(String),
35    /// Encountered multiple text events when only one was expected
36    #[error("Element contains multiple text events")]
37    DoubleText,
38    /// Encountered an unexpected attribute
39    #[error("Found unexpected attribute {0}")]
40    UnexpectedAttribute(String),
41    /// Encountered an unexpected child element
42    #[error("Found unexpected child element <{0}>")]
43    UnexpectedChild(String),
44    /// Encountered an unexpected text event
45    #[error("Found unexpected text")]
46    UnexpectedText,
47    /// Bubbling deserialization error
48    #[error("Error deserializing element <{0}>: {1}")]
49    InnerDeserialiaztionError(String, Box<Error>),
50    /// General deserialization error
51    #[error("Deserialization error: {0}")]
52    Deserialization(String),
53}
54
55impl<T> From<T> for Error
56where
57    T: Into<quick_xml::Error>,
58{
59    fn from(e: T) -> Self {
60        Self::Xml(e.into())
61    }
62}