mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Don't print rustdoc command lines on failure by default
This commit lifts a helper function from invoking rustc to additionally being used for invoking rustdoc. This enables hiding the command line invocation of `rustdoc` by default when it fails, although it's still available to see with `--verbose`. The intention here is to match the behavior of `cargo build` for rustc failures here and was inspired by recently running `cargo doc` and not being able to see the actual failure as the command line ended up taking the whole screen (afterwards I made the screen bigger and that helped too).
This commit is contained in:
parent
4b22dcf25a
commit
1439b3fbe9
@ -376,19 +376,6 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
|
||||
}
|
||||
}
|
||||
|
||||
fn verbose_if_simple_exit_code(err: Error) -> Error {
|
||||
// If a signal on unix (`code == None`) or an abnormal termination
|
||||
// on Windows (codes like `0xC0000409`), don't hide the error details.
|
||||
match err
|
||||
.downcast_ref::<ProcessError>()
|
||||
.as_ref()
|
||||
.and_then(|perr| perr.code)
|
||||
{
|
||||
Some(n) if cargo_util::is_simple_exit_code(n) => VerboseError::new(err).into(),
|
||||
_ => err,
|
||||
}
|
||||
}
|
||||
|
||||
state.running(&rustc);
|
||||
let timestamp = paths::set_invocation_time(&fingerprint_dir)?;
|
||||
if build_plan {
|
||||
@ -510,6 +497,19 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
|
||||
}
|
||||
}
|
||||
|
||||
fn verbose_if_simple_exit_code(err: Error) -> Error {
|
||||
// If a signal on unix (`code == None`) or an abnormal termination
|
||||
// on Windows (codes like `0xC0000409`), don't hide the error details.
|
||||
match err
|
||||
.downcast_ref::<ProcessError>()
|
||||
.as_ref()
|
||||
.and_then(|perr| perr.code)
|
||||
{
|
||||
Some(n) if cargo_util::is_simple_exit_code(n) => VerboseError::new(err).into(),
|
||||
_ => err,
|
||||
}
|
||||
}
|
||||
|
||||
/// Link the compiled target (often of form `foo-{metadata_hash}`) to the
|
||||
/// final target. This must happen during both "Fresh" and "Compile".
|
||||
fn link_targets(cx: &mut Context<'_, '_>, unit: &Unit, fresh: bool) -> CargoResult<Work> {
|
||||
@ -862,6 +862,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
|
||||
},
|
||||
false,
|
||||
)
|
||||
.map_err(verbose_if_simple_exit_code)
|
||||
.with_context(|| format!("could not document `{}`", name));
|
||||
|
||||
if let Err(e) = result {
|
||||
|
@ -2640,3 +2640,24 @@ fn link_to_private_item() {
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn rustdoc_failure_hides_command_line_by_default() {
|
||||
let p = project().file("src/lib.rs", "invalid rust code").build();
|
||||
|
||||
let string_to_test = "\
|
||||
Caused by:
|
||||
process didn't exit successfully[..]rustdoc[..]";
|
||||
|
||||
// `cargo doc` doesn't print the full command line on failures by default
|
||||
p.cargo("doc")
|
||||
.with_stderr_does_not_contain(string_to_test)
|
||||
.with_status(101)
|
||||
.run();
|
||||
|
||||
// ... but it still does so if requested with `--verbose`.
|
||||
p.cargo("doc --verbose")
|
||||
.with_stderr_contains(string_to_test)
|
||||
.with_status(101)
|
||||
.run();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user