summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-02-28 03:29:51 +0000
committerMartin Panter <vadmium+py@gmail.com>2016-02-28 03:29:51 +0000
commit8cacc6300258264ff0598478073a7a0e6a3c1be8 (patch)
tree43479294368be68500c525f32b0f1cf2202478dc /Python
parentb8d75035f2a2ae17d20532fe2a70dce52430442c (diff)
parent3263f6874a96c7b2862bd91460a28e66ac039dbe (diff)
downloadcpython-git-8cacc6300258264ff0598478073a7a0e6a3c1be8.tar.gz
Issue #22836: Merge exception reporting from 3.5
Diffstat (limited to 'Python')
-rw-r--r--Python/errors.c16
-rw-r--r--Python/pythonrun.c8
2 files changed, 19 insertions, 5 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 5ff1e4c81a..47d7c4b992 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -900,8 +900,12 @@ PyErr_WriteUnraisable(PyObject *obj)
if (obj) {
if (PyFile_WriteString("Exception ignored in: ", f) < 0)
goto done;
- if (PyFile_WriteObject(obj, f, 0) < 0)
- goto done;
+ if (PyFile_WriteObject(obj, f, 0) < 0) {
+ PyErr_Clear();
+ if (PyFile_WriteString("<object repr() failed>", f) < 0) {
+ goto done;
+ }
+ }
if (PyFile_WriteString("\n", f) < 0)
goto done;
}
@@ -946,8 +950,12 @@ PyErr_WriteUnraisable(PyObject *obj)
if (v && v != Py_None) {
if (PyFile_WriteString(": ", f) < 0)
goto done;
- if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
- goto done;
+ if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0) {
+ PyErr_Clear();
+ if (PyFile_WriteString("<exception str() failed>", f) < 0) {
+ goto done;
+ }
+ }
}
if (PyFile_WriteString("\n", f) < 0)
goto done;
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 8829699f60..cc2de9a22b 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -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);