From ef85a1ac1510203a06c15f1483b76f2f20b80ede Mon Sep 17 00:00:00 2001 From: Martin Panter Date: Sun, 28 Feb 2016 00:18:43 +0000 Subject: Issue #22836: Keep exception reports sensible despite errors --- Python/pythonrun.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Python/pythonrun.c') diff --git a/Python/pythonrun.c b/Python/pythonrun.c index ece709c337..9b5f62d1ef 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1299,8 +1299,11 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) /* 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(": ", f); + } else if (!PyString_Check(s) || PyString_GET_SIZE(s) != 0) err = PyFile_WriteString(": ", f); @@ -1309,6 +1312,9 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) Py_XDECREF(s); } /* try to write a newline in any case */ + if (err < 0) { + PyErr_Clear(); + } err += PyFile_WriteString("\n", f); } Py_DECREF(value); -- cgit v1.2.1