]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Print a message on python plugin import error.
authorsbh <sergey.belash@opencascade.com>
Thu, 27 Nov 2014 07:49:19 +0000 (10:49 +0300)
committersbh <sergey.belash@opencascade.com>
Thu, 27 Nov 2014 07:49:19 +0000 (10:49 +0300)
src/Config/Config_ModuleReader.cpp

index 57f220e4c655e26222f9ca5136a44b234f92751f..27a03156c95d0f55abd2fad3ff2469acf590b93d 100644 (file)
@@ -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);
 }