File tree 3 files changed +17
-11
lines changed
3 files changed +17
-11
lines changed Original file line number Diff line number Diff line change 11
11
#![ forbid( unsafe_code) ]
12
12
13
13
use clap:: ArgMatches ;
14
- use color_eyre:: eyre:: Result ;
14
+ use color_eyre:: eyre:: { bail , eyre , Result , WrapErr } ;
15
15
16
16
pub mod cmd_line;
17
17
mod logging;
@@ -114,8 +114,11 @@ pub fn run(options: &Options, cmdline_args: &ArgMatches) -> Result<()> {
114
114
. map ( |module| module. include_statement )
115
115
. collect ( ) ;
116
116
117
- // The include_statements should never be empty thanks to the required group in clap
118
- assert ! ( !include_statements. is_empty( ) ) ;
117
+ // The include_statements should never be empty thanks to the required group in clap.
118
+ // Make sure once more, though.
119
+ if include_statements. is_empty ( ) {
120
+ bail ! ( "The populated assembly includes no other files." ) ;
121
+ }
119
122
120
123
// Generate the populated assembly module
121
124
let populated: Module = Input :: new ( ContentType :: Assembly , title, options)
@@ -128,7 +131,8 @@ pub fn run(options: &Options, cmdline_args: &ArgMatches) -> Result<()> {
128
131
// Validate all file names specified on the command line
129
132
if let Some ( files_iterator) = cmdline_args. values_of ( "validate" ) {
130
133
for file in files_iterator {
131
- validation:: validate ( file) ?;
134
+ validation:: validate ( file)
135
+ . wrap_err_with ( || eyre ! ( "Failed to validate file {:?}" , file) ) ?;
132
136
}
133
137
}
134
138
Original file line number Diff line number Diff line change @@ -291,8 +291,12 @@ mod title {
291
291
292
292
let attribute_regex = Regex :: new ( r"\{((?:[[:alnum:]]|[-_])+)\}" ) . expect ( REGEX_ERROR ) ;
293
293
let attribute = attribute_regex. captures ( mod_id) ?;
294
+ let attribute_name = attribute
295
+ . get ( 1 )
296
+ . expect ( "Failed to extract an attribute name. Please report this as a bug" )
297
+ . as_str ( ) ;
294
298
295
- if attribute . get ( 1 ) . unwrap ( ) . as_str ( ) == "context" {
299
+ if attribute_name == "context" {
296
300
// The context attribute is allowed
297
301
None
298
302
} else {
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use std::fs;
2
2
use std:: io;
3
3
use std:: path:: PathBuf ;
4
4
5
- use color_eyre:: eyre:: { Context , Result } ;
5
+ use color_eyre:: eyre:: { eyre , Result , WrapErr } ;
6
6
7
7
use crate :: module:: Module ;
8
8
use crate :: Options ;
@@ -26,7 +26,7 @@ impl Module {
26
26
27
27
io:: stdin ( )
28
28
. read_line ( & mut answer)
29
- . context ( "Failed to read your response" ) ?;
29
+ . wrap_err_with ( || eyre ! ( "Failed to read your response: {:?}" , answer ) ) ?;
30
30
31
31
match answer. trim ( ) . to_lowercase ( ) . as_str ( ) {
32
32
"y" | "yes" => {
@@ -42,10 +42,8 @@ impl Module {
42
42
}
43
43
44
44
// If the target file doesn't exist, try to write to it
45
- fs:: write ( full_path, & self . text ) . context ( format ! (
46
- "Failed to write the `{}` file." ,
47
- & full_path. display( )
48
- ) ) ?;
45
+ fs:: write ( full_path, & self . text )
46
+ . wrap_err_with ( || eyre ! ( "Failed to write the `{}` file." , & full_path. display( ) ) ) ?;
49
47
50
48
// If the write succeeds, print the include statement
51
49
log:: debug!( "Successfully written file `{}`" , & full_path. display( ) ) ;
You can’t perform that action at this time.
0 commit comments