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