From ef9699a42efae36d40f84600ee70603bace65bca Mon Sep 17 00:00:00 2001 From: sbh Date: Thu, 27 Nov 2014 10:49:19 +0300 Subject: [PATCH] Print a message on python plugin import error. --- src/Config/Config_ModuleReader.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index 57f220e4c..27a03156c 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -138,6 +138,24 @@ void Config_ModuleReader::loadScript(const std::string theFileName) /* aquire python thread */ PyGILState_STATE gstate = PyGILState_Ensure(); PyObject* module = PyImport_ImportModule(aPythonFile.c_str()); + + if (!module) { + std::string anErrorMsg = "An error occured while loading " + aPythonFile; + //Get detailed error message: + if (PyErr_Occurred()) { + PyObject *ptype, *pvalue, *ptraceback; + PyErr_Fetch(&ptype, &pvalue, &ptraceback); + std::string aPyError = std::string(PyString_AsString(pvalue)); + if (!aPyError.empty()) { + anErrorMsg += ":\n" + aPyError; + } + Py_XDECREF(ptype); + Py_XDECREF(pvalue); + Py_XDECREF(ptraceback); + } + Events_Error::send(anErrorMsg); + } + /* release python thread */ PyGILState_Release(gstate); } -- 2.39.2