@@ -7,8 +7,6 @@ use std::{io, sync::Arc};
77use miette:: { Diagnostic , NamedSource , SourceSpan } ;
88use thiserror:: Error ;
99
10- use crate :: KdlType ;
11-
1210/// Error type for the provisioning crate
1311#[ derive( Diagnostic , Debug , Error ) ]
1412pub enum Error {
@@ -22,6 +20,9 @@ pub enum Error {
2220 #[ error( "unknown type" ) ]
2321 UnknownType ,
2422
23+ #[ error( "unknown variant" ) ]
24+ UnknownVariant ,
25+
2526 #[ diagnostic( transparent) ]
2627 #[ error( transparent) ]
2728 InvalidType ( #[ from] InvalidType ) ,
@@ -36,69 +37,62 @@ pub enum Error {
3637
3738 #[ diagnostic( transparent) ]
3839 #[ error( transparent) ]
39- ParseError ( #[ from] ParseError ) ,
40+ UnsupportedValue ( #[ from] UnsupportedValue ) ,
4041}
4142
4243/// Merged error for parsing failures
4344/// Returns a list of diagnostics for the user
4445#[ derive( Debug , Diagnostic , Error ) ]
4546#[ error( "failed to parse KDL" ) ]
47+ #[ diagnostic( severity( error) ) ]
4648pub struct ParseError {
49+ #[ source_code]
4750 pub src : NamedSource < Arc < String > > ,
4851 #[ related]
4952 pub diagnostics : Vec < Error > ,
5053}
5154
5255/// Error for invalid types
5356#[ derive( Debug , Diagnostic , Error ) ]
54- #[ error( "property {id} should be {expected_type}, not {found_type} " ) ]
57+ #[ error( "invalid type " ) ]
5558#[ diagnostic( severity( error) ) ]
5659pub struct InvalidType {
57- #[ source_code]
58- pub src : NamedSource < Arc < String > > ,
59-
60- #[ label( "here" ) ]
60+ #[ label]
6161 pub at : SourceSpan ,
62-
63- #[ help]
64- pub advice : Option < String > ,
65-
66- pub id : & ' static str ,
67- pub expected_type : KdlType ,
68- pub found_type : KdlType ,
6962}
7063
7164/// Error for missing mandatory properties
7265#[ derive( Debug , Diagnostic , Error ) ]
73- #[ error( "{name} is missing mandatory property: {id}" ) ]
66+ #[ error( "missing property: {id}" ) ]
7467#[ diagnostic( severity( error) ) ]
7568pub struct MissingProperty {
76- #[ source_code]
77- pub src : NamedSource < Arc < String > > ,
78-
79- #[ label( "here" ) ]
69+ #[ label]
8070 pub at : SourceSpan ,
8171
82- // The name of the node
83- pub name : String ,
84-
85- // The name of the missing property
8672 pub id : & ' static str ,
73+
74+ #[ help]
75+ pub advice : Option < String > ,
8776}
8877
8978/// Error for unsupported node types
9079#[ derive( Debug , Diagnostic , Error ) ]
91- #[ error( "unsupported node: {id }" ) ]
80+ #[ error( "unsupported node: {name }" ) ]
9281#[ diagnostic( severity( warning) ) ]
9382pub struct UnsupportedNode {
94- #[ source_code]
95- pub src : NamedSource < Arc < String > > ,
96-
97- #[ label( "here" ) ]
83+ #[ label]
9884 pub at : SourceSpan ,
9985
100- // The name of the node
101- pub id : String ,
86+ pub name : String ,
87+ }
88+
89+ /// Error for unsupported values
90+ #[ derive( Debug , Diagnostic , Error ) ]
91+ #[ error( "unsupported value" ) ]
92+ #[ diagnostic( severity( error) ) ]
93+ pub struct UnsupportedValue {
94+ #[ label]
95+ pub at : SourceSpan ,
10296
10397 #[ help]
10498 pub advice : Option < String > ,
0 commit comments