1
- use std:: {
2
- num:: { ParseFloatError , ParseIntError } ,
3
- sync:: Arc ,
4
- } ;
1
+ use std:: sync:: Arc ;
5
2
6
3
use miette:: { Diagnostic , SourceSpan } ;
7
4
use thiserror:: Error ;
38
35
/// help: Floating point numbers must be base 10, and have numbers after the decimal point.
39
36
/// ```
40
37
#[ derive( Debug , Diagnostic , Clone , Eq , PartialEq , Error ) ]
41
- #[ error( "Failed to parse KDL. " ) ]
38
+ #[ error( "Failed to parse KDL document " ) ]
42
39
pub struct KdlParseFailure {
43
40
/// Original input that this failure came from.
44
41
#[ source_code]
@@ -53,58 +50,27 @@ pub struct KdlParseFailure {
53
50
///
54
51
/// While generally signifying errors, they can also be treated as warnings.
55
52
#[ derive( Debug , Diagnostic , Clone , Eq , PartialEq , Error ) ]
56
- #[ error( "{kind}" ) ]
53
+ #[ error( "{}" , message . clone ( ) . unwrap_or_else ( || "Unexpected error" . into ( ) ) ) ]
57
54
pub struct KdlDiagnostic {
58
55
/// Shared source for the diagnostic.
59
56
#[ source_code]
60
57
pub input : Arc < String > ,
61
58
62
59
/// Offset in chars of the error.
63
- #[ label( "{}" , label. unwrap_or ( "here" ) ) ]
60
+ #[ label( "{}" , label. clone ( ) . unwrap_or_else ( || "here" . into ( ) ) ) ]
64
61
pub span : SourceSpan ,
65
62
63
+ /// Message for the error itself.
64
+ pub message : Option < String > ,
65
+
66
66
/// Label text for this span. Defaults to `"here"`.
67
- pub label : Option < & ' static str > ,
67
+ pub label : Option < String > ,
68
68
69
69
/// Suggestion for fixing the parser error.
70
70
#[ help]
71
- pub help : Option < & ' static str > ,
71
+ pub help : Option < String > ,
72
72
73
73
/// Severity level for the Diagnostic.
74
74
#[ diagnostic( severity) ]
75
75
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 ,
110
76
}
0 commit comments