From c1b4d1c254cb6d1d50c55e550b9c7f7210c85ec5 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sat, 3 Nov 2012 15:56:05 +0200 Subject: Issue #7317: Display full tracebacks when an error occurs asynchronously. Patch by Alon Horev with update by Alexey Kachayev. --- Python/errors.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 626b16e46f..a2d1a82ddf 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -798,7 +798,12 @@ PyErr_WriteUnraisable(PyObject *obj) PyErr_Fetch(&t, &v, &tb); f = PySys_GetObject("stderr"); if (f != NULL && f != Py_None) { - PyFile_WriteString("Exception ", f); + if (obj) { + PyFile_WriteString("Exception ignored in: ", f); + PyFile_WriteObject(obj, f, 0); + PyFile_WriteString("\n", f); + } + PyTraceBack_Print(tb, f); if (t) { PyObject* moduleName; char* className; @@ -828,15 +833,11 @@ PyErr_WriteUnraisable(PyObject *obj) PyFile_WriteString(className, f); if (v && v != Py_None) { PyFile_WriteString(": ", f); - PyFile_WriteObject(v, f, 0); + PyFile_WriteObject(v, f, Py_PRINT_RAW); } + PyFile_WriteString("\n", f); Py_XDECREF(moduleName); } - if (obj) { - PyFile_WriteString(" in ", f); - PyFile_WriteObject(obj, f, 0); - } - PyFile_WriteString(" ignored\n", f); PyErr_Clear(); /* Just in case */ } Py_XDECREF(t); -- cgit v1.2.1 From 4c3208fadf4fea67e916d8d8c7a04a28c4ad92f9 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Wed, 19 Dec 2012 14:33:35 +0200 Subject: Issue #16719: Get rid of WindowsError. Use OSError instead Patch by Serhiy Storchaka. --- Python/errors.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index a2d1a82ddf..1f955b54f0 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -588,7 +588,7 @@ PyObject *PyErr_SetExcFromWindowsErr(PyObject *exc, int ierr) PyObject *PyErr_SetFromWindowsErr(int ierr) { - return PyErr_SetExcFromWindowsErrWithFilename(PyExc_WindowsError, + return PyErr_SetExcFromWindowsErrWithFilename(PyExc_OSError, ierr, NULL); } PyObject *PyErr_SetFromWindowsErrWithFilename( @@ -597,7 +597,7 @@ PyObject *PyErr_SetFromWindowsErrWithFilename( { PyObject *name = filename ? PyUnicode_DecodeFSDefault(filename) : NULL; PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject( - PyExc_WindowsError, + PyExc_OSError, ierr, name); Py_XDECREF(name); return result; @@ -611,7 +611,7 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename( PyUnicode_FromUnicode(filename, wcslen(filename)) : NULL; PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject( - PyExc_WindowsError, + PyExc_OSError, ierr, name); Py_XDECREF(name); return result; -- cgit v1.2.1 From 21d4e9534aceac9c2753b70bffe4f75ff38ec525 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Wed, 12 Jun 2013 23:29:18 -0400 Subject: Issue #15767: Touch up ModuleNotFoundError usage by import. Forgot to raise ModuleNotFoundError when None is found in sys.modules. This led to introducing the C function PyErr_SetImportErrorSubclass() to make setting ModuleNotFoundError easier. Also updated the reference docs to mention ModuleNotFoundError appropriately. Updated the docs for ModuleNotFoundError to mention the None in sys.modules case. Lastly, it was noticed that PyErr_SetImportError() was not setting an exception when returning None in one case. That issue is now fixed. --- Python/errors.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 1f955b54f0..89021aadd6 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -619,12 +619,25 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename( #endif /* MS_WINDOWS */ PyObject * -PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) +PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg, + PyObject *name, PyObject *path) { + int issubclass; PyObject *args, *kwargs, *error; - if (msg == NULL) + issubclass = PyObject_IsSubclass(exception, PyExc_ImportError); + if (issubclass < 0) { + return NULL; + } + else if (!issubclass) { + PyErr_SetString(PyExc_TypeError, "expected a subclass of ImportError"); + return NULL; + } + + if (msg == NULL) { + PyErr_SetString(PyExc_TypeError, "expected a message argument"); return NULL; + } args = PyTuple_New(1); if (args == NULL) @@ -649,7 +662,7 @@ PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) PyDict_SetItemString(kwargs, "name", name); PyDict_SetItemString(kwargs, "path", path); - error = PyObject_Call(PyExc_ImportError, args, kwargs); + error = PyObject_Call(exception, args, kwargs); if (error != NULL) { PyErr_SetObject((PyObject *)Py_TYPE(error), error); Py_DECREF(error); @@ -661,6 +674,12 @@ PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) return NULL; } +PyObject * +PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) +{ + return PyErr_SetImportErrorSubclass(PyExc_ImportError, msg, name, path); +} + void _PyErr_BadInternalCall(const char *filename, int lineno) { -- cgit v1.2.1