2
2
//
3
3
// SPDX-License-Identifier: MPL-2.0
4
4
5
- use std:: { io , sync :: Arc } ;
5
+ use std:: io ;
6
6
7
+ #[ cfg( feature = "kdl" ) ]
7
8
use miette:: { Diagnostic , NamedSource , SourceSpan } ;
9
+ #[ cfg( feature = "kdl" ) ]
10
+ use std:: sync:: Arc ;
8
11
use thiserror:: Error ;
9
12
13
+ #[ cfg( feature = "kdl" ) ]
10
14
use crate :: KdlType ;
11
15
12
16
/// Error type for the provisioning crate
13
- #[ derive( Diagnostic , Debug , Error ) ]
17
+ #[ cfg_attr( feature = "kdl" , derive( Diagnostic ) ) ]
18
+ #[ derive( Debug , Error ) ]
14
19
pub enum Error {
15
20
#[ error( transparent) ]
16
21
IO ( #[ from] io:: Error ) ,
17
22
23
+ #[ cfg( feature = "kdl" ) ]
18
24
#[ diagnostic( transparent) ]
19
25
#[ error( transparent) ]
20
26
Kdl ( #[ from] kdl:: KdlError ) ,
21
27
28
+ #[ cfg( feature = "kdl" ) ]
22
29
#[ error( "unknown type" ) ]
23
30
UnknownType ,
24
31
25
32
#[ error( "unknown variant" ) ]
26
33
UnknownVariant ,
27
34
35
+ #[ cfg( feature = "kdl" ) ]
28
36
#[ diagnostic( transparent) ]
29
37
#[ error( transparent) ]
30
38
InvalidArguments ( #[ from] InvalidArguments ) ,
31
39
40
+ #[ cfg( feature = "kdl" ) ]
32
41
#[ diagnostic( transparent) ]
33
42
#[ error( transparent) ]
34
43
InvalidType ( #[ from] InvalidType ) ,
35
44
45
+ #[ cfg( feature = "kdl" ) ]
36
46
#[ diagnostic( transparent) ]
37
47
#[ error( transparent) ]
38
48
UnsupportedNode ( #[ from] UnsupportedNode ) ,
39
49
50
+ #[ cfg( feature = "kdl" ) ]
40
51
#[ diagnostic( transparent) ]
41
52
#[ error( transparent) ]
42
53
MissingEntry ( #[ from] MissingEntry ) ,
43
54
55
+ #[ cfg( feature = "kdl" ) ]
44
56
#[ error( "missing node: {0}" ) ]
45
57
MissingNode ( & ' static str ) ,
46
58
59
+ #[ cfg( feature = "kdl" ) ]
47
60
#[ diagnostic( transparent) ]
48
61
#[ error( transparent) ]
49
62
MissingProperty ( #[ from] MissingProperty ) ,
50
63
64
+ #[ cfg( feature = "kdl" ) ]
51
65
#[ diagnostic( transparent) ]
52
66
#[ error( transparent) ]
53
67
UnsupportedValue ( #[ from] UnsupportedValue ) ,
54
68
}
55
69
70
+ #[ cfg( feature = "kdl" ) ]
56
71
/// Merged error for parsing failures
57
72
/// Returns a list of diagnostics for the user
58
73
#[ derive( Debug , Diagnostic , Error ) ]
@@ -65,6 +80,7 @@ pub struct ParseError {
65
80
pub diagnostics : Vec < Error > ,
66
81
}
67
82
83
+ #[ cfg( feature = "kdl" ) ]
68
84
/// Error for invalid types
69
85
#[ derive( Debug , Diagnostic , Error ) ]
70
86
#[ error( "invalid type, expected {expected_type}" ) ]
@@ -77,6 +93,7 @@ pub struct InvalidType {
77
93
pub expected_type : KdlType ,
78
94
}
79
95
96
+ #[ cfg( feature = "kdl" ) ]
80
97
/// Error for missing mandatory properties
81
98
#[ derive( Debug , Diagnostic , Error ) ]
82
99
#[ error( "missing property: {id}" ) ]
@@ -91,6 +108,7 @@ pub struct MissingProperty {
91
108
pub advice : Option < String > ,
92
109
}
93
110
111
+ #[ cfg( feature = "kdl" ) ]
94
112
/// Error for missing mandatory properties
95
113
#[ derive( Debug , Diagnostic , Error ) ]
96
114
#[ error( "missing entry: {id}" ) ]
@@ -105,6 +123,7 @@ pub struct MissingEntry {
105
123
pub advice : Option < String > ,
106
124
}
107
125
126
+ #[ cfg( feature = "kdl" ) ]
108
127
/// Error for unsupported node types
109
128
#[ derive( Debug , Diagnostic , Error ) ]
110
129
#[ error( "unsupported node: {name}" ) ]
@@ -116,6 +135,7 @@ pub struct UnsupportedNode {
116
135
pub name : String ,
117
136
}
118
137
138
+ #[ cfg( feature = "kdl" ) ]
119
139
/// Error for unsupported values
120
140
#[ derive( Debug , Diagnostic , Error ) ]
121
141
#[ error( "unsupported value" ) ]
@@ -128,6 +148,7 @@ pub struct UnsupportedValue {
128
148
pub advice : Option < String > ,
129
149
}
130
150
151
+ #[ cfg( feature = "kdl" ) ]
131
152
/// Error for invalid arguments
132
153
#[ derive( Debug , Diagnostic , Error ) ]
133
154
#[ error( "invalid arguments" ) ]
@@ -140,6 +161,7 @@ pub struct InvalidArguments {
140
161
pub advice : Option < String > ,
141
162
}
142
163
164
+ #[ cfg( feature = "kdl" ) ]
143
165
/// Error for missing types
144
166
#[ derive( Debug , Diagnostic , Error ) ]
145
167
#[ error( "missing type" ) ]
0 commit comments