File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -27,10 +27,12 @@ pub enum ChromaRegexError {
27
27
BytePattern ,
28
28
#[ error( "Pattern that always matches is not allowed" ) ]
29
29
EmptyPattern ,
30
- #[ error( transparent) ]
31
- Regex ( #[ from] regex:: Error ) ,
32
- #[ error( transparent) ]
33
- RegexSyntax ( #[ from] regex_syntax:: Error ) ,
30
+ // NOTE: regex::Error is a large type, so we only store its error message here.
31
+ #[ error( "Unexpected regex error: {0}" ) ]
32
+ Regex ( String ) ,
33
+ // NOTE: regex_syntax::Error is a large type, so we only store its error message here.
34
+ #[ error( "Regex syntax errror: {0}" ) ]
35
+ RegexSyntax ( String ) ,
34
36
}
35
37
36
38
impl ChromaRegex {
@@ -42,15 +44,15 @@ impl ChromaRegex {
42
44
// be Ok(_) becasue we validate the pattern during struct construction. Specifically,
43
45
// we verify that the pattern can be properly parsed and is thus a valid pattern supported
44
46
// by the regex crate.
45
- Ok ( Regex :: new ( & self . pattern ) ? )
47
+ Regex :: new ( & self . pattern ) . map_err ( |e| ChromaRegexError :: Regex ( e . to_string ( ) ) )
46
48
}
47
49
}
48
50
49
51
impl TryFrom < String > for ChromaRegex {
50
52
type Error = ChromaRegexError ;
51
53
52
54
fn try_from ( value : String ) -> Result < Self , Self :: Error > {
53
- let hir = parse ( & value) ?;
55
+ let hir = parse ( & value) . map_err ( |e| ChromaRegexError :: RegexSyntax ( e . to_string ( ) ) ) ?;
54
56
if let Some ( 0 ) = hir. properties ( ) . minimum_len ( ) {
55
57
return Err ( ChromaRegexError :: EmptyPattern ) ;
56
58
}
You can’t perform that action at this time.
0 commit comments