@@ -3,6 +3,7 @@ use cssparser::{ParseError, ParseErrorKind, BasicParseErrorKind};
33use crate :: rules:: Location ;
44use crate :: properties:: custom:: Token ;
55use crate :: values:: string:: CowArcStr ;
6+ use serde:: Serialize ;
67
78#[ derive( Debug , PartialEq , Clone ) ]
89pub struct Error < T > {
@@ -27,10 +28,11 @@ impl ErrorLocation {
2728 }
2829}
2930
30- #[ derive( Debug , PartialEq ) ]
31+ #[ derive( Debug , PartialEq , Serialize ) ]
32+ #[ serde( tag = "type" ) ]
3133pub enum ParserError < ' i > {
3234 /// An unexpected token was encountered.
33- UnexpectedToken ( Token < ' i > ) ,
35+ UnexpectedToken ( # [ serde ( skip ) ] Token < ' i > ) ,
3436 /// The end of the input was encountered unexpectedly.
3537 EndOfInput ,
3638 /// An `@` rule was encountered that was invalid.
@@ -102,9 +104,10 @@ impl<'i> ParserError<'i> {
102104 }
103105}
104106
105- #[ derive( Debug , PartialEq ) ]
107+ #[ derive( Debug , PartialEq , Serialize ) ]
108+ #[ serde( tag = "type" ) ]
106109pub enum SelectorError < ' i > {
107- NoQualifiedNameInAttributeSelector ( Token < ' i > ) ,
110+ NoQualifiedNameInAttributeSelector ( # [ serde ( skip ) ] Token < ' i > ) ,
108111 EmptySelector ,
109112 DanglingCombinator ,
110113 NonCompoundSelector ,
@@ -114,18 +117,18 @@ pub enum SelectorError<'i> {
114117 InvalidState ,
115118 MissingNestingSelector ,
116119 MissingNestingPrefix ,
117- UnexpectedTokenInAttributeSelector ( Token < ' i > ) ,
118- PseudoElementExpectedColon ( Token < ' i > ) ,
119- PseudoElementExpectedIdent ( Token < ' i > ) ,
120- NoIdentForPseudo ( Token < ' i > ) ,
120+ UnexpectedTokenInAttributeSelector ( # [ serde ( skip ) ] Token < ' i > ) ,
121+ PseudoElementExpectedColon ( # [ serde ( skip ) ] Token < ' i > ) ,
122+ PseudoElementExpectedIdent ( # [ serde ( skip ) ] Token < ' i > ) ,
123+ NoIdentForPseudo ( # [ serde ( skip ) ] Token < ' i > ) ,
121124 UnsupportedPseudoClassOrElement ( CowArcStr < ' i > ) ,
122125 UnexpectedIdent ( CowArcStr < ' i > ) ,
123126 ExpectedNamespace ( CowArcStr < ' i > ) ,
124- ExpectedBarInAttr ( Token < ' i > ) ,
125- BadValueInAttr ( Token < ' i > ) ,
126- InvalidQualNameInAttr ( Token < ' i > ) ,
127- ExplicitNamespaceUnexpectedToken ( Token < ' i > ) ,
128- ClassNeedsIdent ( Token < ' i > ) ,
127+ ExpectedBarInAttr ( # [ serde ( skip ) ] Token < ' i > ) ,
128+ BadValueInAttr ( # [ serde ( skip ) ] Token < ' i > ) ,
129+ InvalidQualNameInAttr ( # [ serde ( skip ) ] Token < ' i > ) ,
130+ ExplicitNamespaceUnexpectedToken ( # [ serde ( skip ) ] Token < ' i > ) ,
131+ ClassNeedsIdent ( # [ serde ( skip ) ] Token < ' i > ) ,
129132}
130133
131134impl < ' i > From < SelectorParseErrorKind < ' i > > for SelectorError < ' i > {
@@ -189,7 +192,8 @@ pub struct ErrorWithLocation<T> {
189192
190193pub type MinifyError = ErrorWithLocation < MinifyErrorKind > ;
191194
192- #[ derive( Debug , PartialEq ) ]
195+ #[ derive( Debug , PartialEq , Serialize ) ]
196+ #[ serde( tag = "type" ) ]
193197pub enum MinifyErrorKind {
194198 UnsupportedCustomMediaBooleanLogic { custom_media_loc : Location } ,
195199 CustomMediaNotDefined { name : String } ,
@@ -208,11 +212,13 @@ impl MinifyErrorKind {
208212
209213pub type PrinterError = Error < PrinterErrorKind > ;
210214
211- #[ derive( Debug ) ]
215+ #[ derive( Debug , PartialEq , Serialize ) ]
216+ #[ serde( tag = "type" ) ]
212217pub enum PrinterErrorKind {
213218 FmtError ,
214219 InvalidComposesSelector ,
215- InvalidComposesNesting
220+ InvalidComposesNesting ,
221+ AmbiguousUrlInCustomProperty { url : String }
216222}
217223
218224impl From < std:: fmt:: Error > for PrinterError {
@@ -229,7 +235,8 @@ impl PrinterErrorKind {
229235 match self {
230236 PrinterErrorKind :: InvalidComposesSelector => "The `composes` property can only be used within a simple class selector." . into ( ) ,
231237 PrinterErrorKind :: InvalidComposesNesting => "The `composes` property cannot be used within nested rules." . into ( ) ,
232- PrinterErrorKind :: FmtError => "Printer error" . into ( )
238+ PrinterErrorKind :: FmtError => "Printer error" . into ( ) ,
239+ PrinterErrorKind :: AmbiguousUrlInCustomProperty { .. } => "Ambiguous url() in custom property. Relative paths are resolved from the location the var() is used, not where the custom property is defined. Use an absolute URL instead." . into ( )
233240 }
234241 }
235242}
0 commit comments