mirror of
https://github.com/python/cpython.git
synced 2025-07-08 20:05:28 +00:00
Issue #22836: Keep exception reports sensible despite errors
This commit is contained in:
parent
738f88f688
commit
3263f6874a
5 changed files with 92 additions and 9 deletions
|
@ -766,8 +766,11 @@ print_exception(PyObject *f, PyObject *value)
|
|||
/* only print colon if the str() of the
|
||||
object is not the empty string
|
||||
*/
|
||||
if (s == NULL)
|
||||
if (s == NULL) {
|
||||
PyErr_Clear();
|
||||
err = -1;
|
||||
PyFile_WriteString(": <exception str() failed>", f);
|
||||
}
|
||||
else if (!PyUnicode_Check(s) ||
|
||||
PyUnicode_GetLength(s) != 0)
|
||||
err = PyFile_WriteString(": ", f);
|
||||
|
@ -776,6 +779,9 @@ print_exception(PyObject *f, PyObject *value)
|
|||
Py_XDECREF(s);
|
||||
}
|
||||
/* try to write a newline in any case */
|
||||
if (err < 0) {
|
||||
PyErr_Clear();
|
||||
}
|
||||
err += PyFile_WriteString("\n", f);
|
||||
Py_XDECREF(tb);
|
||||
Py_DECREF(value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue