Fix error displaying exceptions in some cases

Replacing PyErr_Print with PyErr_Display in [0] caused string errors
not to display because PyErr_Display doesn't normalize the exception.

Normalizing before displaying the error resolves this.

[0]: 6a0f98aeef
This commit is contained in:
Campbell Barton 2023-09-19 18:25:28 +10:00
parent 097b97518c
commit 75748f9d7a
2 changed files with 6 additions and 1 deletions

View File

@ -890,6 +890,10 @@ PyObject *PyC_ExceptionBuffer()
PyObject *error_type, *error_value, *error_traceback;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
/* Normalizing is needed because it's possible the error value is a string which
* #PyErr_Display will fail to print. */
PyErr_NormalizeException(&error_type, &error_value, &error_traceback);
/* `io.StringIO()`. */
PyObject *string_io = nullptr;
PyObject *string_io_mod = nullptr;

View File

@ -32,7 +32,8 @@ void PyC_StackSpit(void);
* Return a string containing the full stack trace.
*
* - Only call when `PyErr_Occurred() != 0` .
* - The exception is left in place (without being modified or cleared).
* - The exception is left in place without being manipulated,
* although they will be normalized in order to display them (`PyErr_Print` also does this).
* - `SystemExit` exceptions will exit (so `sys.exit(..)` works, matching `PyErr_Print` behavior).
* - The always returns a Python string (unless exiting where the function doesn't return).
*/