Skip to content

Commit

Permalink
Clarify the default cargo run error message on a non-zero exit code
Browse files Browse the repository at this point in the history
The behavior is the same in the default and verbose modes now:
 - the default mode will not suggest re-running with `--verbose`
 - the verbose mode will not print the binary name.
  • Loading branch information
gkoz committed Oct 13, 2015
1 parent f223eb4 commit 3733493
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/bin/run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cargo::ops;
use cargo::util::{CliResult, CliError, Config};
use cargo::util::{CliResult, CliError, Config, human};
use cargo::util::important_paths::{find_root_manifest_for_cwd};

#[derive(RustcDecodable)]
Expand Down Expand Up @@ -92,7 +92,10 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
None => Ok(None),
Some(err) => {
Err(match err.exit.as_ref().and_then(|e| e.code()) {
Some(i) => CliError::from_error(err, i),
Some(code) => {
let desc = format!("Process finished with exit status {}", code);
CliError::from_boxed(human(desc), code)
}
None => CliError::from_error(err, 101),
})
}
Expand Down
8 changes: 6 additions & 2 deletions tests/test_cargo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ test!(exit_code {
"#);

assert_that(p.cargo_process("run"),
execs().with_status(2));
execs().with_status(2)
.with_stderr(&format!("\
Process finished with exit status 2
",
)));
});

test!(exit_code_verbose {
Expand All @@ -120,7 +124,7 @@ test!(exit_code_verbose {
assert_that(p.cargo_process("run").arg("-v"),
execs().with_status(2)
.with_stderr(&format!("\
Process didn't exit successfully: `target[..]foo` (exit code: 2)
Process finished with exit status 2
",
)));
});
Expand Down

0 comments on commit 3733493

Please sign in to comment.