Skip to content

Commit f2f5512

Browse files
author
Roberto De Ioris
committed
improved exception reporting
1 parent 21d9e59 commit f2f5512

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ void unreal_engine_py_log_error() {
15671567
PyErr_NormalizeException(&type, &value, &traceback);
15681568

15691569
if (!value)
1570-
return;
1570+
goto end;
15711571

15721572
char *msg = NULL;
15731573
PyObject *zero = PyUnicode_AsUTF8String(PyObject_Str(value));
@@ -1576,10 +1576,39 @@ void unreal_engine_py_log_error() {
15761576
}
15771577

15781578
if (!msg)
1579-
return;
1579+
goto end;
15801580

15811581
UE_LOG(LogPython, Error, TEXT("%s"), UTF8_TO_TCHAR(msg));
15821582

1583+
// taken from uWSGI ;)
1584+
if (!traceback) goto end;
1585+
1586+
PyObject *traceback_module = PyImport_ImportModule("traceback");
1587+
if (!traceback_module) {
1588+
return;
1589+
}
1590+
1591+
PyObject *traceback_dict = PyModule_GetDict(traceback_module);
1592+
PyObject *format_exception = PyDict_GetItemString(traceback_dict, "format_exception");
1593+
1594+
if (format_exception) {
1595+
PyObject *ret = PyObject_CallFunctionObjArgs(format_exception, type, value, traceback, NULL);
1596+
if (!ret)
1597+
goto end;
1598+
if (PyList_Check(ret)) {
1599+
for (int i = 0; i < PyList_Size(ret); i++) {
1600+
PyObject *item = PyList_GetItem(ret, i);
1601+
if (item) {
1602+
UE_LOG(LogPython, Error, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(item))));
1603+
}
1604+
}
1605+
}
1606+
else {
1607+
UE_LOG(LogPython, Error, TEXT("%s"), UTF8_TO_TCHAR(PyUnicode_AsUTF8(PyObject_Str(ret))));
1608+
}
1609+
}
1610+
1611+
end:
15831612
PyErr_Clear();
15841613
}
15851614

0 commit comments

Comments
 (0)