1
0
mirror of https://github.com/thp/pyotherside.git synced 2025-01-28 23:52:55 +08:00

Better error reporting (also print everything to the console)

This commit is contained in:
Thomas Perl 2014-01-04 13:14:36 +01:00
parent ee11e74822
commit c14a983713
2 changed files with 7 additions and 5 deletions

View File

@ -99,7 +99,7 @@ QPython::importModule_sync(QString name)
priv->enter(); priv->enter();
PyObject *module = PyImport_ImportModule(moduleName); PyObject *module = PyImport_ImportModule(moduleName);
if (module == NULL) { if (module == NULL) {
emit error(priv->formatExc()); emit error(QString("Cannot import module: %1 (%2)").arg(name).arg(priv->formatExc()));
priv->leave(); priv->leave();
return false; return false;
} }
@ -143,7 +143,7 @@ QPython::evaluate(QString expr)
priv->enter(); priv->enter();
PyObject *o = priv->eval(expr); PyObject *o = priv->eval(expr);
if (o == NULL) { if (o == NULL) {
emit error(priv->formatExc()); emit error(QString("Cannot evaluate '%1' (%2)").arg(expr).arg(priv->formatExc()));
priv->leave(); priv->leave();
return QVariant(); return QVariant();
} }
@ -167,7 +167,7 @@ QPython::call_sync(QString func, QVariant args)
PyObject *callable = priv->eval(func); PyObject *callable = priv->eval(func);
if (callable == NULL) { if (callable == NULL) {
emit error(priv->formatExc()); emit error(QString("Function not found: '%1' (%2)").arg(func).arg(priv->formatExc()));
priv->leave(); priv->leave();
return QVariant(); return QVariant();
} }
@ -183,7 +183,7 @@ QPython::call_sync(QString func, QVariant args)
Py_DECREF(argt); Py_DECREF(argt);
if (o == NULL) { if (o == NULL) {
emit error(priv->formatExc()); emit error(QString("Return value of PyObject call is NULL: %1").arg(priv->formatExc()));
} else { } else {
v = convertPyObjectToQVariant(o); v = convertPyObjectToQVariant(o);
Py_DECREF(o); Py_DECREF(o);
@ -194,7 +194,7 @@ QPython::call_sync(QString func, QVariant args)
return v; return v;
} }
emit error(QString("Not a callable: ") + func); emit error(QString("Not a callable: %1").arg(func));
Py_DECREF(callable); Py_DECREF(callable);
priv->leave(); priv->leave();
return QVariant(); return QVariant();

View File

@ -21,6 +21,7 @@
#include "qpython_priv.h" #include "qpython_priv.h"
#include <QImage> #include <QImage>
#include <QDebug>
static QPythonPriv *priv = NULL; static QPythonPriv *priv = NULL;
@ -239,6 +240,7 @@ cleanup:
Py_XDECREF(value); Py_XDECREF(value);
Py_XDECREF(traceback); Py_XDECREF(traceback);
qDebug() << QString("PyOtherSide error: %1").arg(message);
return message; return message;
} }