Skip to main content

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    TypeIdent,
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(TypeIdent),
19
20    /// Ambiguous type definition
21    ///
22    /// Is raised by the interpreter if it tries to resolve a certain type
23    /// identifier during interpretation of the schema, but multiple matching
24    /// types were found.
25    #[error("Ambiguous type: {0}!")]
26    AmbiguousType(TypeIdent),
27
28    /// Expected simple type.
29    ///
30    /// Expected the specified type to be simple because it is referenced
31    /// in a context that requires a simple type.
32    #[error("Expected simple type: {0}!")]
33    ExpectedSimpleType(TypeIdent),
34
35    /// Expected complex type.
36    ///
37    /// Expected the specified type to be complex because it is referenced
38    /// in a context that requires a complex type.
39    #[error("Expected complex type: {0}!")]
40    ExpectedComplexType(TypeIdent),
41
42    /// Expected dynamic element.
43    ///
44    /// Expected the specified element to be dynamic because it is referenced
45    /// as substitution group.
46    #[error("Expected dynamic element: {0}!")]
47    ExpectedDynamicElement(TypeIdent),
48
49    /// Unknown type.
50    ///
51    /// Is raised if a type identifier could not been resolved to the actual
52    /// type information.
53    #[error("Unknown type: {0}!")]
54    UnknownType(TypeIdent),
55
56    /// Unknown namespace.
57    ///
58    /// Is raised if the namespace URI could not be resolved.
59    #[error("Unknown namespace: {0}!")]
60    UnknownNamespace(Namespace),
61
62    /// Unknown namespace prefix.
63    ///
64    /// Is raised if the namespace prefix could not be resolved.
65    #[error("Unknown namespace prefix: {0}!")]
66    UnknownNamespacePrefix(NamespacePrefix),
67
68    /// Anonymous namespace is undefined.
69    ///
70    /// Before resolving any type that is defined in the anonymous namespace
71    /// you have to add it to the [`Schemas`](crate::models::schema::Schemas)
72    /// by either adding a schema file that uses it (see
73    /// [`add_schema_from_str`](crate::pipeline::parser::Parser::add_schema_from_str)
74    /// or related add_schema_xxx methods) or by defining is manually (see
75    /// [`with_anonymous_namespace`](crate::pipeline::parser::Parser::with_anonymous_namespace)).
76    #[error("Anonymous namespace is undefined!")]
77    AnonymousNamespaceIsUndefined,
78
79    /// Invalid local name.
80    ///
81    /// Is raised if conversion from a raw local name to a string has failed.
82    #[error("Invalid local name `{0}`!")]
83    InvalidLocalName(RawByteStr),
84
85    /// Group is missing the `ref` attribute
86    ///
87    /// Is raised if a group reference in the XML schema is missing the `ref` attribute.
88    #[error("Group is missing the `ref` attribute!")]
89    GroupMissingRef,
90
91    /// Attribute group is missing the `ref` attribute
92    ///
93    /// Is raised if a attribute group reference in the XML schema is missing the `ref` attribute.
94    #[error("Attribute group is missing the `ref` attribute!")]
95    AttributeGroupMissingRef,
96
97    /// Invalid attribute reference.
98    ///
99    /// The attribute specified in the schema is missing some information.
100    #[error("Invalid attribute reference: {0:#?}!")]
101    InvalidAttributeReference(Box<AttributeType>),
102
103    /// Invalid facet.
104    ///
105    /// Is raised if the content of a facet could not be interpreted correctly.
106    #[error("Invalid facet: {0:?}")]
107    InvalidFacet(Facet),
108
109    /// Unable to create type information.
110    ///
111    /// Is raised if the interpreter was not able to generate a `Type` from the
112    /// provided schema information.
113    #[error("Unable to create type information!")]
114    NoType,
115
116    /// The interpreter expected a group type (like `xs:all`, `xs:choice` or `xs:sequence`).
117    #[error("Expected group type!")]
118    ExpectedGroupType,
119
120    /// Circular dependency.
121    ///
122    /// Is raised if the interpreter detects a circular strong dependency between
123    /// types during type generation.
124    #[error("Circular dependency detected for type: {0}!")]
125    CircularDependency(TypeIdent),
126}