# HG changeset patch # User Alain Mazy # Date 1707229974 -3600 # Node ID acdb8d78bf99783496ee908a0634bf5dbadeee0c # Parent b822dcebf9ff0a8ac2993c2849863bab61dbf53b Whatever the SQL error that happens while inserting an instance in DB, remove the attachments that have been added to avoid orphan files diff -r b822dcebf9ff -r acdb8d78bf99 OrthancServer/Sources/ServerContext.cpp --- a/OrthancServer/Sources/ServerContext.cpp Wed Jan 31 13:49:58 2024 +0100 +++ b/OrthancServer/Sources/ServerContext.cpp Tue Feb 06 15:32:54 2024 +0100 @@ -722,15 +722,19 @@ if (ex.GetErrorCode() == ErrorCode_DuplicateResource) { LOG(WARNING) << "Duplicate instance, deleting the attachments"; - - accessor.Remove(dicomInfo); - - if (dicomUntilPixelData.IsValid()) - { - accessor.Remove(dicomUntilPixelData); - } + } + else + { + LOG(ERROR) << "Unexpected error while storing an instance in DB, cancelling and deleting the attachments: " << ex.GetDetails(); } + accessor.Remove(dicomInfo); + + if (dicomUntilPixelData.IsValid()) + { + accessor.Remove(dicomUntilPixelData); + } + throw; }