changeset 3:26762eb9d704

reporting of exceptions
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 27 Mar 2020 11:56:30 +0100
parents df7b4f8a0437
children e3128420249d
files Sources/OnChangeCallback.cpp Sources/OnStoredInstanceCallback.cpp Sources/RestCallbacks.cpp
diffstat 3 files changed, 27 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Sources/OnChangeCallback.cpp	Fri Mar 27 07:59:20 2020 +0100
+++ b/Sources/OnChangeCallback.cpp	Fri Mar 27 11:56:30 2020 +0100
@@ -152,6 +152,13 @@
           PyTuple_SetItem(args.GetPyObject(), 1, PyLong_FromLong(change->GetResourceType()));
           PyTuple_SetItem(args.GetPyObject(), 2, PyUnicode_FromString(change->GetResourceId().c_str()));
           PythonObject result(lock, PyObject_CallObject(changesCallback_, args.GetPyObject()));
+
+          std::string traceback;
+          if (lock.HasErrorOccurred(traceback))
+          {
+            OrthancPlugins::LogError("Error in the Python on-change callback, "
+                                     "traceback:\n" + traceback);
+          }
         }
         catch (OrthancPlugins::PluginException& e)
         {
--- a/Sources/OnStoredInstanceCallback.cpp	Fri Mar 27 07:59:20 2020 +0100
+++ b/Sources/OnStoredInstanceCallback.cpp	Fri Mar 27 11:56:30 2020 +0100
@@ -53,7 +53,18 @@
     PyTuple_SetItem(args2.GetPyObject(), 1, PyUnicode_FromString(instanceId));
 
     PythonObject result(lock, PyObject_CallObject(storedInstanceCallback_, args2.GetPyObject()));
-    return OrthancPluginErrorCode_Success;
+
+    std::string traceback;
+    if (lock.HasErrorOccurred(traceback))
+    {
+      OrthancPlugins::LogError("Error in the Python on-change callback, "
+                               "traceback:\n" + traceback);
+      return OrthancPluginErrorCode_Plugin;
+    }
+    else
+    {
+      return OrthancPluginErrorCode_Success;
+    }
   }
   catch (OrthancPlugins::PluginException& e)
   {
--- a/Sources/RestCallbacks.cpp	Fri Mar 27 07:59:20 2020 +0100
+++ b/Sources/RestCallbacks.cpp	Fri Mar 27 11:56:30 2020 +0100
@@ -95,7 +95,6 @@
       PyTuple_SetItem(args2.GetPyObject(), 1, PyUnicode_FromString(uri));
       // No need to decrement refcount with "PyTuple_SetItem()"
 
-
       /**
        * Construct the named arguments from the "request" argument
        **/
@@ -172,13 +171,19 @@
                                reinterpret_cast<const char*>(request->body), request->bodySize));
       }
 
-
       /**
        * Call the user-defined function
        **/
       PythonObject result(lock, PyObject_Call(
                             (*it)->GetCallback(), args2.GetPyObject(), kw.GetPyObject()));
-      
+
+      std::string traceback;
+      if (lock.HasErrorOccurred(traceback))
+      {
+        OrthancPlugins::LogError("Error in the REST callback, traceback:\n" + traceback);
+        ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
+      }
+
       return;
     }
   }