mirror of https://github.com/pyodide/pyodide.git
Fix #10: Display full exception and traceback
This commit is contained in:
parent
bd6aec63d8
commit
d4eb51b167
|
@ -10,15 +10,41 @@ val pythonExcToJs() {
|
|||
PyObject *type;
|
||||
PyObject *value;
|
||||
PyObject *traceback;
|
||||
PyObject *pystr;
|
||||
|
||||
PyErr_Fetch(&type, &value, &traceback);
|
||||
PyErr_NormalizeException(&type, &value, &traceback);
|
||||
|
||||
val excval("");
|
||||
|
||||
PyObject *tbmod = PyImport_ImportModule("traceback");
|
||||
if (tbmod == NULL) {
|
||||
excval = val("Couldn't get traceback module");
|
||||
} else {
|
||||
PyObject *format_exception = PyObject_GetAttrString(tbmod, "format_exception");
|
||||
if (format_exception == NULL) {
|
||||
excval = val("Couldn't get format_exception function");
|
||||
} else {
|
||||
PyObject *pylines = PyObject_CallFunctionObjArgs
|
||||
(format_exception, type, value, traceback, NULL);
|
||||
PyErr_Print();
|
||||
if (pylines == NULL) {
|
||||
excval = val("Error calling traceback.format_exception");
|
||||
} else {
|
||||
PyObject *newline = PyUnicode_FromString("\n");
|
||||
PyObject *pystr = PyUnicode_Join(newline, pylines);
|
||||
excval = pythonToJs(pystr);
|
||||
Py_DECREF(pystr);
|
||||
Py_DECREF(newline);
|
||||
Py_DECREF(pylines);
|
||||
}
|
||||
Py_DECREF(format_exception);
|
||||
}
|
||||
Py_DECREF(tbmod);
|
||||
}
|
||||
|
||||
pystr = PyObject_Str(value);
|
||||
val Error = val::global("Error");
|
||||
val exc = Error.new_(pythonToJs(pystr));
|
||||
val exc = Error.new_(excval);
|
||||
|
||||
Py_DECREF(pystr);
|
||||
Py_DECREF(type);
|
||||
Py_DECREF(value);
|
||||
Py_DECREF(traceback);
|
||||
|
|
Loading…
Reference in New Issue