Skip to content

Commit

Permalink
Auto merge of #2674 - alexcrichton:less-third-party-cruft, r=brson
Browse files Browse the repository at this point in the history
Don't print extra error info for subcommands

Assume they take care of error printing, so just ferry along the exit status if
they fail

Closes #2673
  • Loading branch information
bors committed May 11, 2016
2 parents e3bc030 + fdc5b07 commit 89a2f2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
22 changes: 14 additions & 8 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions tests/test_cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 89a2f2b

Please sign in to comment.