Skip to main content

redispatch_xml/
error.rs

1//! Error types for Redispatch 2.0 XML.
2
3/// All errors that can occur when parsing, validating, or serializing
4/// Redispatch 2.0 XML documents.
5#[derive(Debug, thiserror::Error)]
6#[non_exhaustive]
7pub enum RedispatchXmlError {
8    /// Low-level XML tokenization or encoding error from `quick-xml`.
9    #[error("XML error: {0}")]
10    Xml(#[from] quick_xml::Error),
11
12    /// Serde-based deserialization error.
13    #[error("deserialization error: {0}")]
14    Deserialize(#[from] quick_xml::de::DeError),
15
16    /// Serde-based serialization error.
17    #[error("serialization error: {0}")]
18    Serialize(String),
19
20    /// A document identifier violates the XSD constraint (1–35 characters).
21    #[error("invalid document id {0:?}: must be 1–35 characters")]
22    InvalidDocumentId(String),
23
24    /// A document version number violates the XSD constraint (integer 1–999).
25    #[error("invalid document version {0}: must be 1–999")]
26    InvalidDocumentVersion(u32),
27
28    /// A UTC timestamp is malformed or uses a non-UTC offset.
29    ///
30    /// All BDEW Redispatch 2.0 timestamps must end with `Z` (UTC).
31    #[error("invalid UTC timestamp {0:?}: must match yyyy-mm-ddThh:mm:ssZ")]
32    InvalidTimestamp(String),
33
34    /// A market participant ID violates the XSD pattern (exactly 13 decimal digits).
35    #[error("invalid market participant id {0:?}: must be exactly 13 decimal digits")]
36    InvalidMarketParticipantId(String),
37
38    /// A time interval string is malformed.
39    ///
40    /// BDEW intervals use minute-precision UTC: `yyyy-mm-ddThh:mmZ/yyyy-mm-ddThh:mmZ`.
41    #[error("invalid time interval {0:?}: must be yyyy-mm-ddThh:mmZ/yyyy-mm-ddThh:mmZ")]
42    InvalidTimeInterval(String),
43
44    /// The root element is not a recognised Redispatch 2.0 document type.
45    #[error("unknown document root element {0:?}: not a supported Redispatch 2.0 document")]
46    UnknownDocumentType(String),
47
48    /// The XML namespace URI on the root element does not match the expected value.
49    #[error("namespace mismatch: expected {expected}, found {found}")]
50    NamespaceMismatch {
51        /// Expected XML namespace URI for this document type.
52        expected: &'static str,
53        /// Actual namespace URI found on the root element.
54        found: String,
55    },
56
57    /// An XSD structural constraint (maxLength, pattern, range, enumeration) was
58    /// violated during explicit validation.
59    #[error("structural validation: {0}")]
60    StructuralError(String),
61}