Don't print extra error info for subcommands
authorAlex Crichton <alex@alexcrichton.com>
Wed, 11 May 2016 23:27:47 +0000 (16:27 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 11 May 2016 23:28:15 +0000 (16:28 -0700)
Assume they take care of error printing, so just ferry along the exit status if
they fail

Closes #2673

src/bin/cargo.rs
tests/test_cargo_install.rs

index 2d0a15d6bf2f3f7e85af5868d73464fe75cffbc6..ad9416d9884083cd9c4de80d06ebf9940568630c 100644 (file)
@@ -13,8 +13,8 @@ use std::path::{Path,PathBuf};
 
 use cargo::core::shell::Verbosity;
 use cargo::execute_main_without_stdin;
-use cargo::util::ChainError;
-use cargo::util::{self, CliResult, lev_distance, Config, human, CargoResult};
+use cargo::util::{self, CliResult, lev_distance, Config, human};
+use cargo::util::CliError;
 use cargo::util::process_builder::process;
 
 #[derive(RustcDecodable)]
@@ -199,7 +199,7 @@ fn find_closest(config: &Config, cmd: &str) -> Option<String> {
 
 fn execute_subcommand(config: &Config,
                       cmd: &str,
-                      args: &[String]) -> CargoResult<()> {
+                      args: &[String]) -> CliResult<()> {
     let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX);
     let path = search_directories(config)
                     .iter()
@@ -212,13 +212,19 @@ fn execute_subcommand(config: &Config,
                 Some(closest) => format!("no such subcommand\n\n\t\
                                           Did you mean `{}`?\n", closest),
                 None => "no such subcommand".to_string()
-            }))
+            }).into())
         }
     };
-    try!(util::process(&command).args(&args[1..]).exec().chain_error(|| {
-        human(format!("third party subcommand `{}` exited unsuccessfully", command_exe))
-    }));
-    Ok(())
+    let err = match util::process(&command).args(&args[1..]).exec() {
+        Ok(()) => return Ok(()),
+        Err(e) => e,
+    };
+
+    if let Some(code) = err.exit.as_ref().and_then(|c| c.code()) {
+        Err(CliError::new("", code))
+    } else {
+        Err(CliError::from_error(err, 101))
+    }
 }
 
 /// List all runnable commands. find_command should always succeed
index 49773d28068a2d1f69772133ef9155c213b0d051..1a99fcc43b6643ee16b4bb79aea5d02c29e4f61e 100644 (file)
@@ -717,11 +717,7 @@ test!(reports_unsuccessful_subcommand_result {
     assert_that(cargo_process("fail"),
                 execs().with_status(101).with_stderr_contains("\
 thread '<main>' panicked at 'explicit panic', [..]
-").with_stderr_contains(format!("\
-[ERROR] third party subcommand `cargo-fail[..]` exited unsuccessfully
-
-To learn more, run the command again with --verbose.
-")));
+"));
 });
 
 test!(git_with_lockfile {