summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/pychrysa.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-11-11 12:08:32 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-11-11 12:08:32 (GMT)
commit4140c074a40ec1e1a68b6c2cb040b8746a7c0e34 (patch)
tree554ed8913faf3c43d137a6c5871f9722fd3271d1 /plugins/pychrysalide/pychrysa.c
parentc301f7e77eaca632a491b5b4417c8e4b9dce2570 (diff)
Printed more details when a Python plugin fails to load.
Diffstat (limited to 'plugins/pychrysalide/pychrysa.c')
-rw-r--r--plugins/pychrysalide/pychrysa.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/plugins/pychrysalide/pychrysa.c b/plugins/pychrysalide/pychrysa.c
index d97cbf0..f998b67 100644
--- a/plugins/pychrysalide/pychrysa.c
+++ b/plugins/pychrysalide/pychrysa.c
@@ -26,7 +26,9 @@
#include <assert.h>
#include <errno.h>
+#include <malloc.h>
#include <pygobject.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
@@ -34,6 +36,7 @@
#include <config.h>
+#include <i18n.h>
#include <gleak.h>
#include <common/cpp.h>
#include <common/environment.h>
@@ -864,7 +867,6 @@ PyThreadState *get_pychrysalide_main_tstate(void)
}
-
/******************************************************************************
* *
* Paramètres : msg = message à faire apparaître à l'écran. *
@@ -886,3 +888,67 @@ void log_pychrysalide_simple_message(LogMessageType type, const char *msg)
log_simple_message(type, msg);
}
+
+
+/******************************************************************************
+* *
+* Paramètres : prefix = message d'introduction à faire apparaître à l'écran.*
+* *
+* Description : Présente dans le journal une exception survenue. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void log_pychrysalide_exception(const char *prefix, ...)
+{
+ va_list ap; /* Compléments argumentaires */
+ char *msg; /* Message complet à imprimer */
+ PyObject *err_type; /* Type d'erreur Python */
+ PyObject *err_value; /* Instance Python d'erreur */
+ PyObject *err_traceback; /* Trace Python associée */
+ PyObject *err_string; /* Description Python d'erreur */
+ const char *err_msg; /* Représentation humaine */
+
+ if (PyErr_Occurred())
+ {
+ /* Base de la communication */
+
+ va_start(ap, prefix);
+
+ vasprintf(&msg, prefix, ap);
+
+ va_end(ap);
+
+ /* Détails complémentaires */
+
+ PyErr_Fetch(&err_type, &err_value, &err_traceback);
+
+ if (err_value == NULL)
+ msg = stradd(msg, _("; no extra information is provided..."));
+
+ else
+ {
+ err_string = PyObject_Str(err_value);
+ err_msg = PyUnicode_AsUTF8(err_string);
+
+ msg = stradd(msg, ": ");
+ msg = stradd(msg, err_msg);
+
+ Py_DECREF(err_string);
+ Py_DECREF(err_value);
+
+ }
+
+ Py_XDECREF(err_traceback);
+ Py_XDECREF(err_type);
+
+ log_pychrysalide_simple_message(LMT_ERROR, msg);
+
+ free(msg);
+
+ }
+
+}