diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 2d0a15d6bf2..ad9416d9884 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -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 { 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 diff --git a/tests/test_cargo_install.rs b/tests/test_cargo_install.rs index 49773d28068..1a99fcc43b6 100644 --- a/tests/test_cargo_install.rs +++ b/tests/test_cargo_install.rs @@ -717,11 +717,7 @@ test!(reports_unsuccessful_subcommand_result { assert_that(cargo_process("fail"), execs().with_status(101).with_stderr_contains("\ thread '
' 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 {