changeset 5414:d5c15e9a63dd

more verbose error
author Alain Mazy <am@osimis.io>
date Wed, 08 Nov 2023 16:02:58 +0100
parents 342b25e120d1
children 2a7a113d791d
files OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp
diffstat 3 files changed, 21 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Wed Nov 08 16:01:42 2023 +0100
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Wed Nov 08 16:02:58 2023 +0100
@@ -1574,7 +1574,8 @@
   
   static bool SaveToMemoryBufferInternal(std::string& buffer,
                                          DcmFileFormat& dicom,
-                                         E_TransferSyntax xfer)
+                                         E_TransferSyntax xfer,
+                                         std::string& errorMessage)
   {
     E_EncodingType encodingType = /*opt_sequenceType*/ EET_ExplicitLength;
 
@@ -1613,14 +1614,24 @@
     {
       // Error
       buffer.clear();
+      errorMessage = std::string(c.text());
       return false;
     }
   }
-  
 
   bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
                                            DcmDataset& dataSet)
   {
+    std::string errorMessageNotUsed;
+    return SaveToMemoryBuffer(buffer, dataSet, errorMessageNotUsed);
+  }
+
+
+
+  bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
+                                           DcmDataset& dataSet,
+                                           std::string& errorMessage)
+  {
     // Determine the transfer syntax which shall be used to write the
     // information to the file. If not possible, switch to the Little
     // Endian syntax, with explicit length.
@@ -1647,7 +1658,7 @@
     ff.validateMetaInfo(xfer);
     ff.removeInvalidGroups();
 
-    return SaveToMemoryBufferInternal(buffer, ff, xfer);
+    return SaveToMemoryBufferInternal(buffer, ff, xfer, errorMessage);
   }
 
 
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h	Wed Nov 08 16:01:42 2023 +0100
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h	Wed Nov 08 16:02:58 2023 +0100
@@ -203,6 +203,10 @@
     static bool SaveToMemoryBuffer(std::string& buffer,
                                    DcmDataset& dataSet);
 
+    static bool SaveToMemoryBuffer(std::string& buffer,
+                                   DcmDataset& dataSet,
+                                   std::string& errorMessage);
+
     static bool Transcode(DcmFileFormat& dicom,
                           DicomTransferSyntax syntax,
                           const DcmRepresentationParameter* representation);
--- a/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Wed Nov 08 16:01:42 2023 +0100
+++ b/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Wed Nov 08 16:02:58 2023 +0100
@@ -939,9 +939,10 @@
 
   void ParsedDicomFile::SaveToMemoryBuffer(std::string& buffer)
   {
-    if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, *GetDcmtkObject().getDataset()))
+    std::string errorMessage;
+    if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, *GetDcmtkObject().getDataset(), errorMessage)
     {
-      throw OrthancException(ErrorCode_InternalError, "Cannot write DICOM file to memory");
+      throw OrthancException(ErrorCode_InternalError, "Cannot write DICOM file to memory, DCMTK error: " + errorMessage);
     }
   }