Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve panic message after exception is normalized #3326

Merged
merged 1 commit into from
Jul 19, 2023

Conversation

davidhewitt
Copy link
Member

Split off from #3306

This was a bug I noticed on pre-3.12 Pythons where the panic message would not be extracted correctly if the PanicException had been normalised. After being fetched by PyO3 the PanicException would have its message reset to "Unwrapped panic from Python code".

src/err/mod.rs Outdated
@@ -299,7 +299,7 @@ impl PyErr {
if ptype.as_ptr() == PanicException::type_object_raw(py).cast() {
let msg: String = pvalue
.as_ref()
.and_then(|obj| obj.extract(py).ok())
.map(|obj| obj.as_ref(py).to_string())
Copy link
Member

Choose a reason for hiding this comment

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

IIRC, we changed the Display impl to call into write_unraisable if the call to PyAny::str fails. Is this appropriate here? Should we call and_then(|obj| obj.as_ref(py).str().ok()) instead since we have an alternative fallback here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, great idea.

@davidhewitt davidhewitt force-pushed the fix-err-panic-normalize branch from a3afe9d to 2e2dde9 Compare July 18, 2023 21:20
@adamreichold adamreichold added this pull request to the merge queue Jul 19, 2023
Merged via the queue into PyO3:main with commit 7958f03 Jul 19, 2023
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.

2 participants