Skip to content

feat: traceback integration - #6342

Open
flying-sheep wants to merge 3 commits into
PyO3:mainfrom
flying-sheep:traceback
Open

feat: traceback integration#6342
flying-sheep wants to merge 3 commits into
PyO3:mainfrom
flying-sheep:traceback

Conversation

@flying-sheep

@flying-sheep flying-sheep commented Aug 22, 2026

Copy link
Copy Markdown

Fixes #1066

TODO: figure out how to do eyre support. color-eyre and stable-eyre have backtraces, but adding all that would add a bunch of features, so I’d welcome some guidance.

@davidhewitt davidhewitt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oooh thanks, interesting!

Comment thread src/conversions/anyhow.rs
let format = traceback.format().expect("expected formatting to work");
let file_path = PathBuf::from(file!());
let file_name = file_path.file_name().and_then(|s| s.to_str()).unwrap();
assert!(format.contains(file_name));

@davidhewitt davidhewitt Aug 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would love to see a more complete test of the full formatted traceback here!

Comment thread src/conversions/anyhow.rs
let err = PyRuntimeError::new_err(format!("{error:?}"));
#[cfg(all(not(Py_LIMITED_API), not(PyPy), not(GraalPy)))]
Python::try_attach(|py| {
if let Ok(tb) = error.backtrace().into_pyobject(py) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder, is it possible to somehow end up with nested Rust -> Python tracebacks in here? I suspect it'd be quite hard to extract that structure...

@flying-sheep flying-sheep Aug 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think so too, as std::backtrace objects can’t be manipulated (thus my addition of btparse).

I think we can at do a better job at “anyhow error that can be downcast to a PyErr” by stitching the tracebacks together.

I still need guidance for stable-eyre and color-eyre – they both use the crates.io backtrace library, which can be modified, so that would be possible.

@bschoenmaeckers bschoenmaeckers Aug 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder, is it possible to somehow end up with nested Rust -> Python tracebacks in here? I suspect it'd be quite hard to extract that structure...

I have a working POC at #5872.
It is blocked by #5876 to get more control on exception creation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Looks great, and seems quite orthogonal to this PR. Of course whichever is merged first would mean the other could benefit from it.

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.

python backtrace integration with Rust's Backtrace API

3 participants