Skip to content

Preserve panic message after exception is normalized#3326

Merged
adamreichold merged 1 commit intoPyO3:mainfrom
davidhewitt:fix-err-panic-normalize
Jul 19, 2023
Merged

Preserve panic message after exception is normalized#3326
adamreichold merged 1 commit intoPyO3:mainfrom
davidhewitt:fix-err-panic-normalize

Conversation

@davidhewitt
Copy link
Copy Markdown
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".

Comment thread src/err/mod.rs Outdated
let msg: String = pvalue
.as_ref()
.and_then(|obj| obj.extract(py).ok())
.map(|obj| obj.as_ref(py).to_string())
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.

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
Copy Markdown
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