22//
33// SPDX-License-Identifier: MPL-2.0
44
5- use std:: { io , sync :: Arc } ;
5+ use std:: io ;
66
7+ #[ cfg( feature = "kdl" ) ]
78use miette:: { Diagnostic , NamedSource , SourceSpan } ;
9+ #[ cfg( feature = "kdl" ) ]
10+ use std:: sync:: Arc ;
811use thiserror:: Error ;
912
13+ #[ cfg( feature = "kdl" ) ]
1014use crate :: KdlType ;
1115
1216/// Error type for the provisioning crate
13- #[ derive( Diagnostic , Debug , Error ) ]
17+ #[ cfg_attr( feature = "kdl" , derive( Diagnostic ) ) ]
18+ #[ derive( Debug , Error ) ]
1419pub enum Error {
1520 #[ error( transparent) ]
1621 IO ( #[ from] io:: Error ) ,
1722
23+ #[ cfg( feature = "kdl" ) ]
1824 #[ diagnostic( transparent) ]
1925 #[ error( transparent) ]
2026 Kdl ( #[ from] kdl:: KdlError ) ,
2127
28+ #[ cfg( feature = "kdl" ) ]
2229 #[ error( "unknown type" ) ]
2330 UnknownType ,
2431
2532 #[ error( "unknown variant" ) ]
2633 UnknownVariant ,
2734
35+ #[ cfg( feature = "kdl" ) ]
2836 #[ diagnostic( transparent) ]
2937 #[ error( transparent) ]
3038 InvalidArguments ( #[ from] InvalidArguments ) ,
3139
40+ #[ cfg( feature = "kdl" ) ]
3241 #[ diagnostic( transparent) ]
3342 #[ error( transparent) ]
3443 InvalidType ( #[ from] InvalidType ) ,
3544
45+ #[ cfg( feature = "kdl" ) ]
3646 #[ diagnostic( transparent) ]
3747 #[ error( transparent) ]
3848 UnsupportedNode ( #[ from] UnsupportedNode ) ,
3949
50+ #[ cfg( feature = "kdl" ) ]
4051 #[ diagnostic( transparent) ]
4152 #[ error( transparent) ]
4253 MissingEntry ( #[ from] MissingEntry ) ,
4354
55+ #[ cfg( feature = "kdl" ) ]
4456 #[ error( "missing node: {0}" ) ]
4557 MissingNode ( & ' static str ) ,
4658
59+ #[ cfg( feature = "kdl" ) ]
4760 #[ diagnostic( transparent) ]
4861 #[ error( transparent) ]
4962 MissingProperty ( #[ from] MissingProperty ) ,
5063
64+ #[ cfg( feature = "kdl" ) ]
5165 #[ diagnostic( transparent) ]
5266 #[ error( transparent) ]
5367 UnsupportedValue ( #[ from] UnsupportedValue ) ,
5468}
5569
70+ #[ cfg( feature = "kdl" ) ]
5671/// Merged error for parsing failures
5772/// Returns a list of diagnostics for the user
5873#[ derive( Debug , Diagnostic , Error ) ]
@@ -65,6 +80,7 @@ pub struct ParseError {
6580 pub diagnostics : Vec < Error > ,
6681}
6782
83+ #[ cfg( feature = "kdl" ) ]
6884/// Error for invalid types
6985#[ derive( Debug , Diagnostic , Error ) ]
7086#[ error( "invalid type, expected {expected_type}" ) ]
@@ -77,6 +93,7 @@ pub struct InvalidType {
7793 pub expected_type : KdlType ,
7894}
7995
96+ #[ cfg( feature = "kdl" ) ]
8097/// Error for missing mandatory properties
8198#[ derive( Debug , Diagnostic , Error ) ]
8299#[ error( "missing property: {id}" ) ]
@@ -91,6 +108,7 @@ pub struct MissingProperty {
91108 pub advice : Option < String > ,
92109}
93110
111+ #[ cfg( feature = "kdl" ) ]
94112/// Error for missing mandatory properties
95113#[ derive( Debug , Diagnostic , Error ) ]
96114#[ error( "missing entry: {id}" ) ]
@@ -105,6 +123,7 @@ pub struct MissingEntry {
105123 pub advice : Option < String > ,
106124}
107125
126+ #[ cfg( feature = "kdl" ) ]
108127/// Error for unsupported node types
109128#[ derive( Debug , Diagnostic , Error ) ]
110129#[ error( "unsupported node: {name}" ) ]
@@ -116,6 +135,7 @@ pub struct UnsupportedNode {
116135 pub name : String ,
117136}
118137
138+ #[ cfg( feature = "kdl" ) ]
119139/// Error for unsupported values
120140#[ derive( Debug , Diagnostic , Error ) ]
121141#[ error( "unsupported value" ) ]
@@ -128,6 +148,7 @@ pub struct UnsupportedValue {
128148 pub advice : Option < String > ,
129149}
130150
151+ #[ cfg( feature = "kdl" ) ]
131152/// Error for invalid arguments
132153#[ derive( Debug , Diagnostic , Error ) ]
133154#[ error( "invalid arguments" ) ]
@@ -140,6 +161,7 @@ pub struct InvalidArguments {
140161 pub advice : Option < String > ,
141162}
142163
164+ #[ cfg( feature = "kdl" ) ]
143165/// Error for missing types
144166#[ derive( Debug , Diagnostic , Error ) ]
145167#[ error( "missing type" ) ]
0 commit comments