1- use std:: {
2- num:: { ParseFloatError , ParseIntError } ,
3- sync:: Arc ,
4- } ;
1+ use std:: sync:: Arc ;
52
63use miette:: { Diagnostic , SourceSpan } ;
74use thiserror:: Error ;
3835/// help: Floating point numbers must be base 10, and have numbers after the decimal point.
3936/// ```
4037#[ derive( Debug , Diagnostic , Clone , Eq , PartialEq , Error ) ]
41- #[ error( "Failed to parse KDL. " ) ]
38+ #[ error( "Failed to parse KDL document " ) ]
4239pub struct KdlParseFailure {
4340 /// Original input that this failure came from.
4441 #[ source_code]
@@ -53,58 +50,27 @@ pub struct KdlParseFailure {
5350///
5451/// While generally signifying errors, they can also be treated as warnings.
5552#[ derive( Debug , Diagnostic , Clone , Eq , PartialEq , Error ) ]
56- #[ error( "{kind}" ) ]
53+ #[ error( "{}" , message . clone ( ) . unwrap_or_else ( || "Unexpected error" . into ( ) ) ) ]
5754pub struct KdlDiagnostic {
5855 /// Shared source for the diagnostic.
5956 #[ source_code]
6057 pub input : Arc < String > ,
6158
6259 /// Offset in chars of the error.
63- #[ label( "{}" , label. unwrap_or ( "here" ) ) ]
60+ #[ label( "{}" , label. clone ( ) . unwrap_or_else ( || "here" . into ( ) ) ) ]
6461 pub span : SourceSpan ,
6562
63+ /// Message for the error itself.
64+ pub message : Option < String > ,
65+
6666 /// Label text for this span. Defaults to `"here"`.
67- pub label : Option < & ' static str > ,
67+ pub label : Option < String > ,
6868
6969 /// Suggestion for fixing the parser error.
7070 #[ help]
71- pub help : Option < & ' static str > ,
71+ pub help : Option < String > ,
7272
7373 /// Severity level for the Diagnostic.
7474 #[ diagnostic( severity) ]
7575 pub severity : miette:: Severity ,
76-
77- /// Specific error kind for this parser error.
78- pub kind : KdlErrorKind ,
79- }
80-
81- /// A type representing additional information specific to the type of error being returned.
82- #[ derive( Debug , Diagnostic , Clone , Eq , PartialEq , Error ) ]
83- pub enum KdlErrorKind {
84- /// An error occurred while parsing an integer.
85- #[ error( transparent) ]
86- #[ diagnostic( code( kdl:: parse_int) ) ]
87- ParseIntError ( ParseIntError ) ,
88-
89- /// An error occurred while parsing a floating point number.
90- #[ error( transparent) ]
91- #[ diagnostic( code( kdl:: parse_float) ) ]
92- ParseFloatError ( ParseFloatError ) ,
93-
94- /// Tried to parse a negative number as an unsigned integer.
95- #[ error( "Tried to parse a negative number as an unsigned integer." ) ]
96- #[ diagnostic( code( kdl:: negative_unsigned) ) ]
97- NegativeUnsignedError ,
98-
99- /// Generic parsing error. The given context string denotes the component
100- /// that failed to parse.
101- #[ error( "Expected {0}." ) ]
102- #[ diagnostic( code( kdl:: parse_component) ) ]
103- Context ( & ' static str ) ,
104-
105- /// Generic unspecified error. If this is returned, the call site should
106- /// be annotated with context, if possible.
107- #[ error( "An unspecified parse error occurred." ) ]
108- #[ diagnostic( code( kdl:: other) ) ]
109- Other ,
11076}
0 commit comments