Merge pull request #34366 from SUSE/wip-mgr-fix-python-traceback

mgr/PyModule: fix missing tracebacks in handle_pyerror()

Reviewed-by: Sebastian Wagner <sebastian.wagner@suse.com>
Reviewed-by: Sage Weil <sage@redhat.com>
Reviewed-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2020-04-08 15:29:34 +08:00 committed by GitHub
commit b8cac4f109
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,7 @@ std::string handle_pyerror()
PyObject *exc, *val, *tb;
object formatted_list, formatted;
PyErr_Fetch(&exc, &val, &tb);
PyErr_NormalizeException(&exc, &val, &tb);
handle<> hexc(exc), hval(allow_null(val)), htb(allow_null(tb));
object traceback(import("traceback"));
if (!tb) {
@ -56,6 +57,7 @@ std::string handle_pyerror()
std::stringstream ss;
ss << PyUnicode_AsUTF8(name_attr) << ": " << PyUnicode_AsUTF8(val);
Py_XDECREF(name_attr);
ss << "\nError processing exception object: " << peek_pyerror();
return ss.str();
}
} else {
@ -69,6 +71,7 @@ std::string handle_pyerror()
std::stringstream ss;
ss << PyUnicode_AsUTF8(name_attr) << ": " << PyUnicode_AsUTF8(val);
Py_XDECREF(name_attr);
ss << "\nError processing exception object: " << peek_pyerror();
return ss.str();
}
}