]> git.lizzy.rs Git - rust.git/commitdiff
clippy_dev: Pass stderr to CommandFailed
authorPhilipp Hansch <dev@phansch.net>
Sun, 31 Jan 2021 10:17:37 +0000 (11:17 +0100)
committerPhilipp Hansch <dev@phansch.net>
Sun, 31 Jan 2021 10:21:33 +0000 (11:21 +0100)
clippy_dev/src/fmt.rs

index 6b528d219df27d62a37f859f0900f3f6402b2b58..4d0fdadbd85d184d6b927db81211764c729e5153 100644 (file)
@@ -8,7 +8,7 @@
 
 #[derive(Debug)]
 pub enum CliError {
-    CommandFailed(String),
+    CommandFailed(String, String),
     IoError(io::Error),
     RustfmtNotInstalled,
     WalkDirError(walkdir::Error),
@@ -75,8 +75,8 @@ fn try_run(context: &FmtContext) -> Result<bool, CliError> {
 
     fn output_err(err: CliError) {
         match err {
-            CliError::CommandFailed(command) => {
-                eprintln!("error: A command failed! `{}`", command);
+            CliError::CommandFailed(command, stderr) => {
+                eprintln!("error: A command failed! `{}`\nstderr: {}", command, stderr);
             },
             CliError::IoError(err) => {
                 eprintln!("error: {}", err);
@@ -136,12 +136,16 @@ fn exec(
         println!("{}", format_command(&program, &dir, args));
     }
 
-    let mut child = Command::new(&program).current_dir(&dir).args(args.iter()).spawn()?;
-    let code = child.wait()?;
-    let success = code.success();
+    let child = Command::new(&program).current_dir(&dir).args(args.iter()).spawn()?;
+    let output = child.wait_with_output()?;
+    let success = output.status.success();
 
     if !context.check && !success {
-        return Err(CliError::CommandFailed(format_command(&program, &dir, args)));
+        let stderr = std::str::from_utf8(&output.stderr).unwrap_or("");
+        return Err(CliError::CommandFailed(
+            format_command(&program, &dir, args),
+            String::from(stderr),
+        ));
     }
 
     Ok(success)
@@ -177,7 +181,10 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
     {
         Err(CliError::RustfmtNotInstalled)
     } else {
-        Err(CliError::CommandFailed(format_command(&program, &dir, args)))
+        Err(CliError::CommandFailed(
+            format_command(&program, &dir, args),
+            std::str::from_utf8(&output.stderr).unwrap_or("").to_string(),
+        ))
     }
 }