Skip to content

Add Error::new_with_backtrace - #463

Open
sb123sb123 wants to merge 1 commit into
dtolnay:masterfrom
sb123sb123:fix/462-new-with-backtrace
Open

sb123sb123 wants to merge 1 commit into
dtolnay:masterfrom
sb123sb123:fix/462-new-with-backtrace

Conversation

@sb123sb123

Copy link
Copy Markdown

Closes #462

Summary

Error::new captures or discovers a backtrace while constructing the error, but stable Rust does not provide a way to attach a backtrace that was captured earlier. This is needed by callers that capture a backtrace before constructing their anyhow error.

This adds Error::new_with_backtrace(error, backtrace) under the existing std feature. It stores the supplied backtrace through the existing error construction path, preserving the existing error chain and default Error::new behavior. A regression test verifies that the supplied backtrace is retained.

Tests

  • cargo fmt --all -- --check
  • cargo test (including 26 doctests)
  • cargo clippy --all-targets -- -D warnings
  • cargo doc --no-deps
  • cargo check --all-features
  • cargo check --no-default-features
  • cargo +nightly test --test test_backtrace -- --nocapture
  • cargo +nightly check --no-default-features

AI assistance: OpenAI Codex (GPT-5.6 Luna)

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.

Construct Error with existing backtrace

1 participant