Skip to content

Commit

Permalink
Merge pull request #21005 from rjfd/wip-mgr-fix-error-handling
Browse files Browse the repository at this point in the history
mgr: fixes python error handling

Reviewed-by: John Spray <john.spray@redhat.com>
Reviewed-by: Kefu Chai <kchai@redhat.com>
Reviewed-by: Sebastian Wagner <sebastian.wagner@suse.com>
Reviewed-by: Tim Serong <tserong@suse.com>
  • Loading branch information
rjfd committed Mar 27, 2018
2 parents d5e54fd + 072699d commit b4a7955
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/mgr/PyModule.cc
Expand Up @@ -40,10 +40,30 @@ std::string handle_pyerror()
object traceback(import("traceback"));
if (!tb) {
object format_exception_only(traceback.attr("format_exception_only"));
formatted_list = format_exception_only(hexc, hval);
try {
formatted_list = format_exception_only(hexc, hval);
} catch (error_already_set const &) {
// error while processing exception object
// returning only the exception string value
PyObject *name_attr = PyObject_GetAttrString(exc, "__name__");
std::stringstream ss;
ss << PyString_AsString(name_attr) << ": " << PyString_AsString(val);
Py_XDECREF(name_attr);
return ss.str();
}
} else {
object format_exception(traceback.attr("format_exception"));
formatted_list = format_exception(hexc,hval, htb);
try {
formatted_list = format_exception(hexc, hval, htb);
} catch (error_already_set const &) {
// error while processing exception object
// returning only the exception string value
PyObject *name_attr = PyObject_GetAttrString(exc, "__name__");
std::stringstream ss;
ss << PyString_AsString(name_attr) << ": " << PyString_AsString(val);
Py_XDECREF(name_attr);
return ss.str();
}
}
formatted = str("").join(formatted_list);
return extract<std::string>(formatted);
Expand Down

0 comments on commit b4a7955

Please sign in to comment.