changeset 102:ed994991a20b

improved error handling
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Feb 2022 08:37:31 +0100
parents eb6ac5a801d1
children d2259c4cd677
files Sources/IncomingInstanceFilter.cpp Sources/ReceivedInstanceCallback.cpp
diffstat 2 files changed, 27 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/Sources/IncomingInstanceFilter.cpp	Wed Feb 23 07:35:37 2022 +0100
+++ b/Sources/IncomingInstanceFilter.cpp	Wed Feb 23 08:37:31 2022 +0100
@@ -113,9 +113,8 @@
 
 PyObject* RegisterIncomingCStoreInstanceFilter(PyObject* module, PyObject* args)
 {
-  OrthancPlugins::LogError("The version of your Orthanc SDK doesn't provide OrthancPluginRegisterIncomingCStoreInstanceFilter()");
-  Py_INCREF(Py_None);
-  return Py_None;
+  PyErr_SetString(PyExc_RuntimeError, "The version of your Orthanc SDK doesn't provide OrthancPluginRegisterIncomingCStoreInstanceFilter()");
+  return NULL;
 }
 
 void FinalizeIncomingCStoreInstanceFilter()
--- a/Sources/ReceivedInstanceCallback.cpp	Wed Feb 23 07:35:37 2022 +0100
+++ b/Sources/ReceivedInstanceCallback.cpp	Wed Feb 23 08:37:31 2022 +0100
@@ -72,36 +72,38 @@
       OrthancPluginReceivedInstanceAction resultCode = static_cast<OrthancPluginReceivedInstanceAction>(PyLong_AsLong(returnCode));
 
       if (resultCode == OrthancPluginReceivedInstanceAction_KeepAsIs ||
-        resultCode == OrthancPluginReceivedInstanceAction_Discard)
+          resultCode == OrthancPluginReceivedInstanceAction_Discard)
       {
         return resultCode;
       }
-
-      char* pythonBuffer = NULL;
-      Py_ssize_t pythonSize = 0;
-      if (PyBytes_AsStringAndSize(modifiedDicom, &pythonBuffer, &pythonSize) == 1)
-      {
-        OrthancPlugins::LogError("Cannot access the byte buffer returned by the Python received instance callback");
-        return OrthancPluginReceivedInstanceAction_KeepAsIs;
-      }
       else
       {
-        OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), modifiedDicomBuffer, pythonSize);
+        char* pythonBuffer = NULL;
+        Py_ssize_t pythonSize = 0;
+        if (PyBytes_AsStringAndSize(modifiedDicom, &pythonBuffer, &pythonSize) == 1)
+        {
+          OrthancPlugins::LogError("Cannot access the byte buffer returned by the Python received instance callback");
+          return OrthancPluginReceivedInstanceAction_KeepAsIs;
+        }
+        else
+        {
+          OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), modifiedDicomBuffer, pythonSize);
         
-        if (pythonSize != 0)
-        {
-          if (modifiedDicomBuffer->data == NULL)
+          if (pythonSize != 0)
           {
-            OrthancPlugins::LogError("Cannot allocate memory in the Python received instance callback");
-            return OrthancPluginReceivedInstanceAction_KeepAsIs;
+            if (modifiedDicomBuffer->data == NULL)
+            {
+              OrthancPlugins::LogError("Cannot allocate memory in the Python received instance callback");
+              return OrthancPluginReceivedInstanceAction_KeepAsIs;
+            }
+            else
+            {
+              memcpy(modifiedDicomBuffer->data, pythonBuffer, pythonSize);
+            }
           }
-          else
-          {
-            memcpy(modifiedDicomBuffer->data, pythonBuffer, pythonSize);
-          }
+
+          return OrthancPluginReceivedInstanceAction_Modify;
         }
-
-        return OrthancPluginReceivedInstanceAction_Modify;
       }
     }
   }
@@ -146,9 +148,8 @@
 
 PyObject* RegisterReceivedInstanceCallback(PyObject* module, PyObject* args)
 {
-  OrthancPlugins::LogError("The version of your Orthanc SDK doesn't provide OrthancPluginRegisterReceivedInstanceCallback()");
-  Py_INCREF(Py_None);
-  return Py_None;
+  PyErr_SetString(PyExc_RuntimeError, "The version of your Orthanc SDK doesn't provide OrthancPluginRegisterReceivedInstanceCallback()");
+  return NULL;
 }
 
 void FinalizeReceivedInstanceCallback()