@@ -8,7 +8,7 @@ use walkdir::WalkDir;
88
99#[ derive( Debug ) ]
1010pub enum CliError {
11- CommandFailed ( String ) ,
11+ CommandFailed ( String , String ) ,
1212 IoError ( io:: Error ) ,
1313 RustfmtNotInstalled ,
1414 WalkDirError ( walkdir:: Error ) ,
@@ -75,8 +75,8 @@ pub fn run(check: bool, verbose: bool) {
7575
7676 fn output_err ( err : CliError ) {
7777 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 ) ;
8080 } ,
8181 CliError :: IoError ( err) => {
8282 eprintln ! ( "error: {}" , err) ;
@@ -136,12 +136,16 @@ fn exec(
136136 println ! ( "{}" , format_command( & program, & dir, args) ) ;
137137 }
138138
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 ( ) ;
142142
143143 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+ ) ) ;
145149 }
146150
147151 Ok ( success)
@@ -177,7 +181,10 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
177181 {
178182 Err ( CliError :: RustfmtNotInstalled )
179183 } 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+ ) )
181188 }
182189}
183190
0 commit comments