@@ -8,7 +8,7 @@ use walkdir::WalkDir;
8
8
9
9
#[ derive( Debug ) ]
10
10
pub enum CliError {
11
- CommandFailed ( String ) ,
11
+ CommandFailed ( String , String ) ,
12
12
IoError ( io:: Error ) ,
13
13
RustfmtNotInstalled ,
14
14
WalkDirError ( walkdir:: Error ) ,
@@ -75,8 +75,8 @@ pub fn run(check: bool, verbose: bool) {
75
75
76
76
fn output_err ( err : CliError ) {
77
77
match err {
78
- CliError :: CommandFailed ( command) => {
79
- eprintln ! ( "error: A command failed! `{}`" , command) ;
78
+ CliError :: CommandFailed ( command, stderr ) => {
79
+ eprintln ! ( "error: A command failed! `{}`\n stderr: {} " , command, stderr ) ;
80
80
} ,
81
81
CliError :: IoError ( err) => {
82
82
eprintln ! ( "error: {}" , err) ;
@@ -136,12 +136,16 @@ fn exec(
136
136
println ! ( "{}" , format_command( & program, & dir, args) ) ;
137
137
}
138
138
139
- let mut child = Command :: new ( & program) . current_dir ( & dir) . args ( args. iter ( ) ) . spawn ( ) ?;
140
- let code = child. wait ( ) ?;
141
- let success = code . success ( ) ;
139
+ let child = Command :: new ( & program) . current_dir ( & dir) . args ( args. iter ( ) ) . spawn ( ) ?;
140
+ let output = child. wait_with_output ( ) ?;
141
+ let success = output . status . success ( ) ;
142
142
143
143
if !context. check && !success {
144
- return Err ( CliError :: CommandFailed ( format_command ( & program, & dir, args) ) ) ;
144
+ let stderr = std:: str:: from_utf8 ( & output. stderr ) . unwrap_or ( "" ) ;
145
+ return Err ( CliError :: CommandFailed (
146
+ format_command ( & program, & dir, args) ,
147
+ String :: from ( stderr) ,
148
+ ) ) ;
145
149
}
146
150
147
151
Ok ( success)
@@ -177,7 +181,10 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
177
181
{
178
182
Err ( CliError :: RustfmtNotInstalled )
179
183
} else {
180
- Err ( CliError :: CommandFailed ( format_command ( & program, & dir, args) ) )
184
+ Err ( CliError :: CommandFailed (
185
+ format_command ( & program, & dir, args) ,
186
+ std:: str:: from_utf8 ( & output. stderr ) . unwrap_or ( "" ) . to_string ( ) ,
187
+ ) )
181
188
}
182
189
}
183
190
0 commit comments