Skip to content

fix(cli): avoid Rust backtrace for test failures - #36851

Open
Tiancheng-Xu wants to merge 5 commits into
denoland:mainfrom
Tiancheng-Xu:fix/36832-rust-backtrace
Open

Tiancheng-Xu wants to merge 5 commits into
denoland:mainfrom
Tiancheng-Xu:fix/36832-rust-backtrace

Conversation

@Tiancheng-Xu

@Tiancheng-Xu Tiancheng-Xu commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Root cause

exit_for_error rendered non-JavaScript errors with anyhow Debug formatting. When RUST_BACKTRACE=1, anyhow appends its captured backtrace to that output. Using alternate Display formatting removed the backtrace but also collapsed the established multi-line error-chain layout, which broke existing CLI output expectations. The fix now preserves the Debug-rendered error chain and removes only the exact captured-backtrace suffix.

Validation

  • RUSTFLAGS="--cfg tokio_unstable" cargo build -p deno
  • RUSTFLAGS="--cfg tokio_unstable" cargo test -p integration_tests --test integration -- test::test_failure_does_not_print_rust_backtrace — 1 passed
  • RUSTFLAGS="--cfg tokio_unstable" cargo test -p specs_tests --test specs -- fmt::malformed_config::fmt_with_malformed_config2 — 1 passed, confirming the existing error-chain layout is preserved
  • RUSTFLAGS="--cfg tokio_unstable" cargo clippy --manifest-path cli/Cargo.toml --bin deno --no-deps — completed with existing repository warnings
  • rustfmt --edition 2024 --check cli/lib.rs tests/integration/test_tests.rs
  • git diff --check

The new full CI run for the current head is still in progress. A separate local npm integration attempt could not complete because the test server could not download its pinned esbuild fixture from raw.githubusercontent.com; it was not counted as passing.

AI tools assisted with implementation and review. I verified the final changes and the validation results reported above.

@Tiancheng-Xu
Tiancheng-Xu marked this pull request as ready for review September 16, 2026 13:17
Copilot AI lite review requested due to automatic review settings September 16, 2026 13:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new regression test should assert a couple of expected failure markers (eg. “error: Test failed” / “boom”) to avoid false positives where an unrelated failure would also omit “Stack backtrace:”.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adjusts Deno CLI’s top-level error rendering so ordinary failures (not panics) don’t print an anyhow-captured Rust backtrace when RUST_BACKTRACE=1, while still keeping useful error-chain context. This targets deno test failures that previously emitted irrelevant Stack backtrace: noise.

Changes:

  • Switch exit_for_error to use anyhow’s alternate Display formatting ({error:#}) instead of Debug ({error:?}) for non-JS errors.
  • Add an integration regression test ensuring a failing deno test run with RUST_BACKTRACE=1 does not include Stack backtrace:.
File summaries
File Description
cli/lib.rs Changes CLI error formatting to avoid printing anyhow debug backtraces on normal errors.
tests/integration/test_tests.rs Adds a regression test covering deno test failure output with RUST_BACKTRACE=1.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/integration/test_tests.rs Outdated
Comment on lines +177 to +179
output.assert_exit_code(1);
assert_not_contains!(output.combined_output(), "Stack backtrace:");
} No newline at end of file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 09dcb649b. The regression now asserts error: Test failed and Error: boom before checking that Stack backtrace: is absent. Fresh validation: RUSTFLAGS="--cfg tokio_unstable" cargo test -p integration_tests --test integration -- test::test_failure_does_not_print_rust_backtrace — 1 passed.

@Tiancheng-Xu

Tiancheng-Xu commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor Author

The failed debug integration/spec jobs on the previous head exposed that alternate Display formatting also collapsed existing multi-line error chains. Fixed in d6abb273f by retaining the existing Debug rendering and removing only the exact captured-backtrace suffix.

Fresh validation on the current implementation:

  • target regression: 1/1 passed
  • representative existing error-format spec: 1/1 passed
  • cargo build -p deno: passed
  • cargo clippy --manifest-path cli/Cargo.toml --bin deno --no-deps: completed with existing repository warnings only

The new full CI is still running. Its current Linux and macOS ARM debug specs failures are both check_node_builtin_modules expecting a different Node type diagnostic, unrelated to the two changed files; I have not changed that snapshot.

@CLAassistant

CLAassistant commented Sep 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Tiancheng-Xu

Copy link
Copy Markdown
Contributor Author

The remaining failing test on 27178d410 is node_compat::parallel::test-fs-read-stream-pos.js: it timed out after 10,000 ms, with 1 failed out of 1,243 tests. The log does not show an assertion failure for this test.

Could a maintainer rerun the failed Linux node-compat shard? I don't have permission to rerun the upstream workflow. I haven't changed the test or increased its timeout; a rerun would help distinguish a transient timeout from a reproducible failure before making a source change.

NetOpWibby pushed a commit to theende/ende that referenced this pull request Nov 7, 2026
With RUST_BACKTRACE=1, anyhow captures a backtrace for every error and
its Debug output appends it, so an ordinary failure such as
"error: Test failed" printed the CLI's own Rust frames, which say
nothing about the failure. exit_for_error keeps the Debug layout (with
its "Caused by:" chain) and drops only the captured backtrace suffix.
Panics still print their backtrace.

Squashed: 4 PR commits and a merge of main, as the net diff.

(cherry picked from commit de093b9de64482df6317aaf46c262505c10db609 through d6abb273f76762f900eb90b8421fe58de38ccb24)

Upstream: denoland/deno#36851
nightness added a commit to Brainwires/deno that referenced this pull request Nov 15, 2026
With RUST_BACKTRACE=1, anyhow captures a backtrace for every error and
its Debug output appends it, so an ordinary failure such as
"error: Test failed" printed the CLI's own Rust frames, which say
nothing about the failure. exit_for_error keeps the Debug layout (with
its "Caused by:" chain) and drops only the captured backtrace suffix.
Panics still print their backtrace.

Squashed: 4 PR commits and a merge of main, as the net diff.
DENEXT.md item 415.

Ported-from: theende/ende@4850e5c327
Upstream-Issue: denoland#36832
Upstream: denoland#36851
Co-authored-by: Tiancheng-Xu <[email protected]>

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EAACL8TVEpJt2b5ywcrydw
nightness added a commit to Brainwires/deno that referenced this pull request Nov 15, 2026
With RUST_BACKTRACE=1, anyhow captures a backtrace for every error and
its Debug output appends it, so an ordinary failure such as
"error: Test failed" printed the CLI's own Rust frames, which say
nothing about the failure. exit_for_error keeps the Debug layout (with
its "Caused by:" chain) and drops only the captured backtrace suffix.
Panics still print their backtrace.

Squashed: 4 PR commits and a merge of main, as the net diff.
DENEXT.md item 414.

Ported-from: theende/ende@4850e5c327
Upstream-Issue: denoland#36832
Upstream: denoland#36851
Co-authored-by: Tiancheng-Xu <[email protected]>

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EAACL8TVEpJt2b5ywcrydw
nightness added a commit to Brainwires/deno that referenced this pull request Nov 15, 2026
With RUST_BACKTRACE=1, anyhow captures a backtrace for every error and
its Debug output appends it, so an ordinary failure such as
"error: Test failed" printed the CLI's own Rust frames, which say
nothing about the failure. exit_for_error keeps the Debug layout (with
its "Caused by:" chain) and drops only the captured backtrace suffix.
Panics still print their backtrace.

Squashed: 4 PR commits and a merge of main, as the net diff.
DENEXT.md item 414.

Ported-from: theende/ende@4850e5c327
Upstream-Issue: denoland#36832
Upstream: denoland#36851
Co-authored-by: Tiancheng-Xu <[email protected]>

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EAACL8TVEpJt2b5ywcrydw

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RUST_BACKTRACE=1 prints a useless Rust stack backtrace on ordinary deno test failures

3 participants