framework/
error.rs

1// Lints
2// Todo: remove when `https://github.com/rust-lang/rust/issues/147648` will be resolved.
3#![allow(unused_assignments)]
4
5use miette::{
6    SourceSpan,
7};
8
9#[derive(Debug)]
10#[derive(miette::Diagnostic)]
11#[derive(thiserror::Error)]
12pub enum Error {
13    #[error("Unknown choice")]
14    ChoiceUnknown {
15        #[label]
16        value: SourceSpan,
17    },
18
19    #[error("Classification not in catalogue")]
20    ClassificationNotInCatalogue {
21        #[label]
22        name: SourceSpan,
23    },
24
25    #[error("Classification length does not match catalogue")]
26    #[diagnostic(help("Catalogue has {expecting}"))]
27    ClassificationLengthMissmatch {
28        #[label]
29        length: SourceSpan,
30
31        expecting: usize,
32    },
33
34    #[error("Unknown classification")]
35    ClassificationUnknown {
36        #[label]
37        value: SourceSpan,
38    },
39
40    #[error("Unknown display type")]
41    DisplayUnknown {
42        #[label]
43        value: SourceSpan,
44    },
45
46    #[error("Field cannot end with a reverse")]
47    FieldEndWithReverse {
48        #[label]
49        reverse: SourceSpan,
50    },
51
52    #[error("Expecting a {expecting} field")]
53    FieldKindNot {
54        expecting: &'static str,
55        found: String,
56
57        #[label("it has type {found} instead")]
58        value: SourceSpan,
59    },
60
61    #[error("Unknown field of table {table}")]
62    FieldUnknown {
63        table: String,
64
65        #[label]
66        value: SourceSpan,
67    },
68
69    #[error("Hash error: {message}")]
70    HashError {
71        message: String,
72    },
73
74    #[error("Framework version has changed")]
75    #[diagnostic(help("Calculated {calculated}"))]
76    HashChanged {
77        calculated: String,
78        #[label]
79        existing: SourceSpan,
80    },
81
82    #[error("Identifier too long")]
83    IdentifierTooLong {
84        #[label]
85        parent: SourceSpan,
86    },
87
88    #[error(transparent)]
89    #[diagnostic(transparent)]
90    Name(#[from] parse::NameError),
91
92    #[error(transparent)]
93    #[diagnostic(transparent)]
94    Path(#[from] parse::PathError),
95
96    #[error("Minimum must be less than maximum")]
97    RangeBackwards {
98        #[label]
99        range: SourceSpan,
100    },
101
102    #[error("Expecting <restrict national=/>")]
103    RestrictExpectNational {
104        #[label]
105        field: SourceSpan,
106    },
107
108    #[error("Not expecting <restrict/>")]
109    RestrictExpectNone {
110        #[label]
111        field: SourceSpan,
112    },
113
114    #[error("Expecting <restrict state=/>")]
115    RestrictExpectState {
116        #[label]
117        field: SourceSpan,
118    },
119
120    #[error("Restrict value must be same type as field")]
121    RestrictKinds {
122        #[label("field is type {field_kind}")]
123        field: SourceSpan,
124        field_kind: String,
125
126        #[label("value is type {value_kind}")]
127        value: SourceSpan,
128        value_kind: String,
129    },
130
131    #[error("Reverse join not satisfied")]
132    #[diagnostic(help("Looking for unique index with single refer field to previous table"))]
133    ReverseUnknown {
134        #[label]
135        value: SourceSpan,
136    },
137
138    #[error("StringField did not build a FieldKind::String")]
139    StringFieldInvalid {
140        #[label]
141        value: SourceSpan,
142    },
143
144    #[error("Either 'choice', 'name' or 'names' must be set")]
145    SuggestEmpty {
146        #[label]
147        value: SourceSpan,
148    },
149
150    #[error("Cannot mix a 'choice' field with 'identifier', 'name' or 'names'")]
151    SuggestMixedChoice {
152        #[label]
153        value: SourceSpan,
154    },
155
156    #[error("Cannot mix a 'name' field with 'names'")]
157    SuggestMixedName {
158        #[label]
159        value: SourceSpan,
160    },
161
162    #[error("Unknown table")]
163    TableUnknown {
164        #[label]
165        value: SourceSpan,
166    },
167
168    #[error(transparent)]
169    #[diagnostic(transparent)]
170    Xml(#[from] parse::xml::ParseError),
171}