Skip to main content

mx20022_parse/
error.rs

1//! Error types for XML parsing and serialization.
2
3use thiserror::Error;
4
5/// Errors that can occur during ISO 20022 XML parsing or serialization.
6#[derive(Debug, Error)]
7pub enum ParseError {
8    /// XML deserialization failed.
9    #[error("XML deserialization error: {0}")]
10    Deserialize(#[from] quick_xml::DeError),
11
12    /// XML deserialization failed for a document whose envelope was
13    /// successfully detected. `context` carries the dotted message
14    /// identifier (e.g. `"pacs.008.001.13"`); `source` is the underlying
15    /// `quick_xml` diagnostic.
16    #[error("XML deserialization error in {context}: {source}")]
17    DeserializeIn {
18        /// Free-form description of the envelope being parsed.
19        context: String,
20        /// The underlying `quick_xml` deserialization error.
21        #[source]
22        source: quick_xml::DeError,
23    },
24
25    /// XML serialization failed.
26    #[error("XML serialization error: {0}")]
27    Serialize(#[from] quick_xml::SeError),
28
29    /// An I/O error occurred.
30    #[error("I/O error: {0}")]
31    Io(#[from] std::io::Error),
32
33    /// The XML document does not have a valid ISO 20022 envelope.
34    #[error("invalid envelope: {0}")]
35    InvalidEnvelope(String),
36}