xsd_parser/interpreter/
error.rs

1use thiserror::Error;
2
3use crate::misc::RawByteStr;
4use crate::schema::xs::AttributeType;
5use crate::schema::{Namespace, NamespacePrefix};
6use crate::types::Ident;
7
8/// error raised by the [`Interpreter`](super::Interpreter).
9#[derive(Debug, Error)]
10pub enum Error {
11    /// Type has already been defined.
12    ///
13    /// Is raised if a new type with an already existing identifier is added
14    /// to the [`Types`](crate::types::Types) structure.
15    #[error("Type has already been defined: {0}!")]
16    TypeAlreadyDefined(Ident),
17
18    /// Expected dynamic element.
19    ///
20    /// Expected the specified element to be dynamic because it is referenced
21    /// as substitution group.
22    #[error("Expected dynamic element: {0}!")]
23    ExpectedDynamicElement(Ident),
24
25    /// Unknown type.
26    ///
27    /// Is raised if a type identifier could not been resolved to the actual
28    /// type information.
29    #[error("Unknown type: {0}!")]
30    UnknownType(Ident),
31
32    /// Unknown element.
33    ///
34    /// Is raised if an element referenced inside the XML schema could not be resolved.
35    #[error("Unknown element: {0}!")]
36    UnknownElement(Ident),
37
38    /// Unknown attribute.
39    ///
40    /// Is raised if an attribute referenced inside the XML schema could not be resolved.
41    #[error("Unknown attribute: {0}!")]
42    UnknownAttribute(String),
43
44    /// Unknown namespace.
45    ///
46    /// Is raised if the namespace URI could not be resolved.
47    #[error("Unknown namespace: {0}!")]
48    UnknownNamespace(Namespace),
49
50    /// Unknown namespace prefix.
51    ///
52    /// Is raised if the namespace prefix could not be resolved.
53    #[error("Unknown namespace prefix: {0}!")]
54    UnknownNamespacePrefix(NamespacePrefix),
55
56    /// Invalid value.
57    ///
58    /// Is raised if a value from the XML schema is malformed or invalid.
59    #[error("Invalid value for `{0}`!")]
60    InvalidValue(&'static str),
61
62    /// Invalid local name.
63    ///
64    /// Is raised if conversion from a raw local name to a string has failed.
65    #[error("Invalid local name `{0}`!")]
66    InvalidLocalName(RawByteStr),
67
68    /// Group is missing the `ref` attribute
69    ///
70    /// Is raised if a group reference in the XML schema is missing the `ref` attribute.
71    #[error("Group is missing the `ref` attribute!")]
72    GroupMissingRef,
73
74    /// Attribute group is missing the `ref` attribute
75    ///
76    /// Is raised if a attribute group reference in the XML schema is missing the `ref` attribute.
77    #[error("Attribute group is missing the `ref` attribute!")]
78    AttributeGroupMissingRef,
79
80    /// Invalid attribute reference.
81    ///
82    /// The attribute specified in the schema is missing some information.
83    #[error("Invalid attribute reference: {0:#?}!")]
84    InvalidAttributeReference(Box<AttributeType>),
85
86    /// Internal error.
87    ///
88    /// IS raised if an internal error occurred. Check the log output for more details.
89    #[error("Internal error!")]
90    InternalError,
91
92    /// The interpreter expected a group type (like `xs:all`, `xs:choice` or `xs:sequence`).
93    #[error("Expected group type!")]
94    ExpectedGroupType,
95}