rokm · GitHub

@rokm @htgoebel

The windowed+debug variant of the bootloader on Windows (runw_d.exe) has the
ability to display information about the uncaught exception that terminated
the program execution. I.e., after the Failed to execute script <name> dialog,
it shows dialogs with Error: <message> and Traceback: <traceback>.
Unfortunately, the extra dialogs always showed "Error: NULL" and "Traceback:
NULL". This was because as per docs, the preceding PyErr_Print() call clears
the error information, so PyErr_Fetch() comes up empty.
This change rearranges the calls so that exception information is retrieved
before PyErr_Print() clears it. Thus the exception message and the traceback
can be displayed in subsequent dialogs.
The PyErr_Fetch() call, that retrieves error indicator data, is now paired
with PyErr_Restore() call, which seems to be necessary in order for
PyErr_Print() to properly process SystemExit() exceptions.
As PyErr_Restore() releases the reference to error indicator data, we now
create a deep copy of exception message string and traceback string. The
extraction code is moved into helper functions, which simplifies the code in
pyi_launch_run_scripts() itself.

Read the original on github.com ↗