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