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