Skip to main content

xsd_parser/pipeline/generator/
error.rs

1use thiserror::Error;
2
3use crate::{
4    models::{code::InvalidIdentPath, schema::NamespaceId, TypeIdent},
5    pipeline::generator::ValueGeneratorMode,
6};
7
8/// Error that might be raised by the [`Generator`](super::Generator).
9#[derive(Debug, Error)]
10pub enum Error {
11    /// Unknown type identifier.
12    ///
13    /// Is raised if a specific identifier could not be resolved to it's
14    /// corresponding type information.
15    #[error("Unknown type identifier: {0}!")]
16    UnknownType(TypeIdent),
17
18    /// Unknown namespace.
19    ///
20    /// Is raised if a specific namespace id could not be resolved to it's
21    /// corresponding namespace information.
22    #[error("Unknown namespace: {0:?}!")]
23    UnknownNamespace(NamespaceId),
24
25    /// Invalid default value.
26    ///
27    /// Is raised if the default value for an attribute defined in the schema
28    /// could not be converted to a suitable default code snippet.
29    #[error("Invalid default value for type (ident={ident:?}, value={value}, mode: {mode:?})!")]
30    InvalidDefaultValue {
31        /// The identifier of the type for which the value should be generated.
32        ident: TypeIdent,
33
34        /// The value that should be generated.
35        value: String,
36
37        /// The mode that determines how the value should be generated.
38        mode: ValueGeneratorMode,
39    },
40
41    /// Invalid identifier.
42    ///
43    /// Is raised if the user passed a invalid identifier.
44    #[error("{0}")]
45    InvalidIdentifier(
46        #[from]
47        #[source]
48        InvalidIdentPath,
49    ),
50}