Skip to content

Commit

Permalink
Auto merge of #13387 - alexcrichton:hide-rustdoc-cli-on-failure, r=epage
Browse files Browse the repository at this point in the history
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).

Fixes #13386
  • Loading branch information
bors committed Feb 2, 2024
2 parents 4b22dcf + 1439b3f commit 258fa84
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 258fa84

Please sign in to comment.