mirror of https://github.com/KLayout/klayout.git
Script errors now include the class for better readability in Python, normalizing errors in Python
This commit is contained in:
parent
a7e648c82b
commit
7ac51337ca
|
|
@ -124,9 +124,9 @@ static void ui_exception_handler_tl (const tl::Exception &ex, QWidget *parent)
|
|||
|
||||
if (gsi_excpt->line () > 0) {
|
||||
tl::error << gsi_excpt->sourcefile () << ":" << gsi_excpt->line () << ": "
|
||||
<< gsi_excpt->msg () << tl::to_string (QObject::tr (" (class ")) << gsi_excpt->cls () << ")";
|
||||
<< gsi_excpt->msg ();
|
||||
} else {
|
||||
tl::error << gsi_excpt->msg () << tl::to_string (QObject::tr (" (class ")) << gsi_excpt->cls () << ")";
|
||||
tl::error << gsi_excpt->msg ();
|
||||
}
|
||||
|
||||
lay::RuntimeErrorForm error_dialog (parent, "ruby_error_form", gsi_excpt);
|
||||
|
|
|
|||
|
|
@ -44,17 +44,19 @@ void check_error ()
|
|||
{
|
||||
PyObject *py_exc_type = NULL, *py_exc_value = NULL, *py_exc_traceback = NULL;
|
||||
PyErr_Fetch (&py_exc_type, &py_exc_value, &py_exc_traceback);
|
||||
PythonRef exc_type (py_exc_type);
|
||||
PythonRef exc_value (py_exc_value);
|
||||
PythonRef exc_traceback (py_exc_traceback);
|
||||
if (py_exc_type != NULL) {
|
||||
|
||||
std::string exc_cls ("unknown");
|
||||
const char *c = ((PyTypeObject *) exc_type.get ())->tp_name;
|
||||
if (c) {
|
||||
exc_cls = c;
|
||||
}
|
||||
PyErr_NormalizeException (&py_exc_type, &py_exc_value, &py_exc_traceback);
|
||||
|
||||
if (exc_type) {
|
||||
PythonRef exc_type (py_exc_type);
|
||||
PythonRef exc_value (py_exc_value);
|
||||
PythonRef exc_traceback (py_exc_traceback);
|
||||
|
||||
std::string exc_cls ("unknown");
|
||||
const char *c = ((PyTypeObject *) exc_type.get ())->tp_name;
|
||||
if (c) {
|
||||
exc_cls = c;
|
||||
}
|
||||
|
||||
// fetch traceback
|
||||
// TODO: really decref the stack trace? how about the other objects in the stack trace?
|
||||
|
|
|
|||
|
|
@ -79,14 +79,30 @@ BacktraceElement::to_string() const
|
|||
// -------------------------------------------------------------------
|
||||
// ScriptError implementation
|
||||
|
||||
static std::string make_basic_msg (const char *text, const char *cls)
|
||||
{
|
||||
std::string msg;
|
||||
if (*cls) {
|
||||
msg = cls;
|
||||
}
|
||||
if (*cls && *text) {
|
||||
msg += ": ";
|
||||
}
|
||||
if (*text) {
|
||||
msg += text;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
ScriptError::ScriptError (const char *msg, const char *cls, const std::vector<BacktraceElement> &backtrace)
|
||||
: tl::Exception (msg), m_line (-1), m_cls (cls), m_backtrace (backtrace)
|
||||
: tl::Exception (make_basic_msg (msg, cls)), m_line (-1), m_cls (cls), m_backtrace (backtrace)
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
ScriptError::ScriptError (const char *msg, const char *sourcefile, int line, const char *cls, const std::vector<BacktraceElement> &backtrace)
|
||||
: tl::Exception (msg), m_sourcefile (sourcefile), m_line (line), m_cls (cls), m_backtrace (backtrace)
|
||||
: tl::Exception (make_basic_msg (msg, cls)), m_sourcefile (sourcefile), m_line (line), m_cls (cls), m_backtrace (backtrace)
|
||||
{
|
||||
translate_includes ();
|
||||
}
|
||||
|
|
@ -103,8 +119,8 @@ ScriptError::msg () const
|
|||
std::string m = basic_msg ();
|
||||
|
||||
if (! m_context.empty ()) {
|
||||
m += tl::to_string (tr (" in ")) + m_context;
|
||||
}
|
||||
m += tl::to_string (tr (" in ")) + m_context;
|
||||
}
|
||||
|
||||
for (std::vector<BacktraceElement>::const_iterator bt = backtrace ().begin (); bt != backtrace ().end (); ++bt) {
|
||||
m += "\n ";
|
||||
|
|
|
|||
Loading…
Reference in New Issue