Skip to content

Conversation

@iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Dec 12, 2021

Previously print_exception_recursive, and some other functions, called PyErr_Clear before returning. Now each of these functions returns the error so that we go back to the topmost _PyErr_Display and the PyErr_Clear happens there. So the whole thing exits, rather than just this one recursive call.

https://bugs.python.org/issue45635

@iritkatriel iritkatriel changed the title bpo-45636: Do not suppress errors in the various print_exception func… bpo-45635: Do not suppress errors in the various print_exception func… Dec 12, 2021
@iritkatriel iritkatriel changed the title bpo-45635: Do not suppress errors in the various print_exception func… bpo-45635: Do not suppress errors in the various print_exception functions Dec 12, 2021
@iritkatriel iritkatriel changed the title bpo-45635: Do not suppress errors in the various print_exception functions bpo-45635: Do not suppress errors in functions called from _PyErr_Display Dec 12, 2021
@erlend-aasland
Copy link
Contributor

Previously print_exception_recursive, and some other functions, called PyErr_Clear before returning. Now each of these functions returns the error so that we go back to the topmost _PyErr_Display and the PyErr_Clear happens there. So the whole thing exits, rather than just this one recursive call.

Makes sense to me.

Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

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

Looks very good! I want to go over this once more in a day or two, if that's ok with you.

@iritkatriel
Copy link
Member Author

Of course, this is not urgent at all.

Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

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

LGTM, but AFAICT we are unable to actually test this because we must fail in something like PyFile_WriteString (or OOM) for print_exception_recursive to actually return -1. I'm wondering if we could provoke a write error in some kind of way.

// the end of that one since we don't support multi-line error
// messages.
if (end_lineno > lineno) {
end_offset = (error_line != NULL) ? line_size : -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

This branch is not covered by the test suite, AFAICS.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe make a bpo about this? I just copied this piece of code around, so it's not a new problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

This code is fairly recent:

commit a77aac4
Author: Pablo Galindo [email protected]
Date: Fri Apr 23 14:27:05 2021 +0100

Copy link
Member Author

Choose a reason for hiding this comment

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

If the test is added in a separate PR it can be backported to 3.10.

Copy link
Member Author

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

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

I was also thinking how one could test these error conditions. I think we would require some debug-mode-only macro that fails on the Nth time, and then run the test for all relevant values of N. It could be quite slow.

// the end of that one since we don't support multi-line error
// messages.
if (end_lineno > lineno) {
end_offset = (error_line != NULL) ? line_size : -1;
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe make a bpo about this? I just copied this piece of code around, so it's not a new problem.

@iritkatriel iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Dec 16, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit d6f6bbb 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Dec 16, 2021
@iritkatriel iritkatriel merged commit 8d6155e into python:main Dec 16, 2021
@iritkatriel iritkatriel deleted the bpo-45635-pythonrun2 branch December 16, 2021 23:00
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.

4 participants