# HG changeset patch
# User Alain Mazy <am@osimis.io>
# Date 1699455778 -3600
# Node ID d5c15e9a63dd79461583da6ff34d3ee7bd4090f3
# Parent  342b25e120d15d48b6e2448586d6876d054a045b
more verbose error

diff -r 342b25e120d1 -r d5c15e9a63dd OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp
--- 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);
   }
 
 
diff -r 342b25e120d1 -r d5c15e9a63dd OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h
--- 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);
diff -r 342b25e120d1 -r d5c15e9a63dd OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp
--- 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);
     }
   }