@@ -9,44 +9,35 @@ pub type Result<T> = core::result::Result<T, Error>;
99/// Simple error enum that wraps common error types
1010#[ derive( Debug , Error ) ]
1111pub enum Error {
12- /// Regex compilation failed
13- #[ error( "Invalid regex: {0}" ) ]
14- Regex ( #[ from] regex:: Error ) ,
15-
16- /// File system operation failed
17- #[ error( "File system error: {0}" ) ]
18- Io ( #[ from] std:: io:: Error ) ,
19-
20- /// Directory walking failed
21- #[ error( "Directory walking error: {0}" ) ]
22- WalkDir ( #[ from] walkdir:: Error ) ,
23-
24- /// User provided ambiguous replacement syntax
25- #[ error( "{}" , format_ambiguous_replacement( ambiguous_whole) ) ]
26- AmbiguousReplacementSyntax {
27- ambiguous_whole : String ,
28- ambiguous_head : String ,
29- } ,
12+ /// Regex compilation failed
13+ #[ error( "Invalid regex: {0}" ) ]
14+ Regex ( #[ from] regex:: Error ) ,
15+
16+ /// File system operation failed
17+ #[ error( "File system error: {0}" ) ]
18+ Io ( #[ from] std:: io:: Error ) ,
19+
20+ /// Directory walking failed
21+ #[ error( "Directory walking error: {0}" ) ]
22+ WalkDir ( #[ from] walkdir:: Error ) ,
23+
24+ /// User provided ambiguous replacement syntax
25+ #[ error( "{}" , format_ambiguous_replacement( ambiguous_whole) ) ]
26+ AmbiguousReplacementSyntax { ambiguous_whole : String , ambiguous_head : String } ,
3027}
3128
3229/// Helper function to create error display for `AmbiguousReplacementSyntax`
3330fn format_ambiguous_replacement ( ambiguous_whole : & str ) -> String {
34- // separate digits from dollar
35- let without_dollar = ambiguous_whole. trim_start_matches ( '$' ) ;
36- let digits: String = without_dollar
37- . chars ( )
38- . take_while ( |c| c. is_ascii_digit ( ) )
39- . collect ( ) ;
40- let text: String = without_dollar
41- . chars ( )
42- . skip_while ( |c| c. is_ascii_digit ( ) )
43- . collect ( ) ;
44-
45- format ! (
46- "Ambiguous replacement syntax: '{}' is read as '{}' but you probably meant '{}'. Use '{}' instead (or use {{}} around capture group identifiers)." ,
47- ambiguous_whole. yellow( ) ,
48- format!( "${{{without_dollar}}}" ) . red( ) ,
49- format!( "${{{}}}{text}" , digits) . green( ) ,
50- format!( "${{{}}}{text}" , digits) . green( )
51- )
31+ // separate digits from dollar
32+ let without_dollar = ambiguous_whole. trim_start_matches ( '$' ) ;
33+ let digits: String = without_dollar. chars ( ) . take_while ( |c| c. is_ascii_digit ( ) ) . collect ( ) ;
34+ let text: String = without_dollar. chars ( ) . skip_while ( |c| c. is_ascii_digit ( ) ) . collect ( ) ;
35+
36+ format ! (
37+ "Ambiguous replacement syntax: '{}' is read as '{}' but you probably meant '{}'. Use '{}' instead (or use {{}} around capture group identifiers)." ,
38+ ambiguous_whole. yellow( ) ,
39+ format!( "${{{without_dollar}}}" ) . red( ) ,
40+ format!( "${{{}}}{text}" , digits) . green( ) ,
41+ format!( "${{{}}}{text}" , digits) . green( )
42+ )
5243}
0 commit comments