Skip to content

Commit 89a2f2b

Browse files
committed
Auto merge of #2674 - alexcrichton:less-third-party-cruft, r=brson
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
2 parents e3bc030 + fdc5b07 commit 89a2f2b

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/bin/cargo.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use std::path::{Path,PathBuf};
1313

1414
use cargo::core::shell::Verbosity;
1515
use cargo::execute_main_without_stdin;
16-
use cargo::util::ChainError;
17-
use cargo::util::{self, CliResult, lev_distance, Config, human, CargoResult};
16+
use cargo::util::{self, CliResult, lev_distance, Config, human};
17+
use cargo::util::CliError;
1818
use cargo::util::process_builder::process;
1919

2020
#[derive(RustcDecodable)]
@@ -199,7 +199,7 @@ fn find_closest(config: &Config, cmd: &str) -> Option<String> {
199199

200200
fn execute_subcommand(config: &Config,
201201
cmd: &str,
202-
args: &[String]) -> CargoResult<()> {
202+
args: &[String]) -> CliResult<()> {
203203
let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX);
204204
let path = search_directories(config)
205205
.iter()
@@ -212,13 +212,19 @@ fn execute_subcommand(config: &Config,
212212
Some(closest) => format!("no such subcommand\n\n\t\
213213
Did you mean `{}`?\n", closest),
214214
None => "no such subcommand".to_string()
215-
}))
215+
}).into())
216216
}
217217
};
218-
try!(util::process(&command).args(&args[1..]).exec().chain_error(|| {
219-
human(format!("third party subcommand `{}` exited unsuccessfully", command_exe))
220-
}));
221-
Ok(())
218+
let err = match util::process(&command).args(&args[1..]).exec() {
219+
Ok(()) => return Ok(()),
220+
Err(e) => e,
221+
};
222+
223+
if let Some(code) = err.exit.as_ref().and_then(|c| c.code()) {
224+
Err(CliError::new("", code))
225+
} else {
226+
Err(CliError::from_error(err, 101))
227+
}
222228
}
223229

224230
/// List all runnable commands. find_command should always succeed

tests/test_cargo_install.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,7 @@ test!(reports_unsuccessful_subcommand_result {
717717
assert_that(cargo_process("fail"),
718718
execs().with_status(101).with_stderr_contains("\
719719
thread '<main>' panicked at 'explicit panic', [..]
720-
").with_stderr_contains(format!("\
721-
[ERROR] third party subcommand `cargo-fail[..]` exited unsuccessfully
722-
723-
To learn more, run the command again with --verbose.
724-
")));
720+
"));
725721
});
726722

727723
test!(git_with_lockfile {

0 commit comments

Comments
 (0)