# HG changeset patch # User Sebastien Jodogne # Date 1443194979 -7200 # Node ID 2e692c83e2f32daf8a0048e86cfe7f6c2fd4c3b1 # Parent 9f34ebfaf2c9b01573d9a9498269bbaeaf7809f7 improved custom error login diff -r 9f34ebfaf2c9 -r 2e692c83e2f3 Core/Enumerations.cpp --- a/Core/Enumerations.cpp Fri Sep 25 16:47:05 2015 +0200 +++ b/Core/Enumerations.cpp Fri Sep 25 17:29:39 2015 +0200 @@ -44,6 +44,11 @@ // "Resources/GenerateErrorCodes.py" const char* EnumerationToString(ErrorCode error) { + if (error >= ErrorCode_START_PLUGINS) + { + return "Error encountered within some plugin"; + } + switch (error) { case ErrorCode_InternalError: diff -r 9f34ebfaf2c9 -r 2e692c83e2f3 OrthancServer/main.cpp --- a/OrthancServer/main.cpp Fri Sep 25 16:47:05 2015 +0200 +++ b/OrthancServer/main.cpp Fri Sep 25 17:29:39 2015 +0200 @@ -333,7 +333,7 @@ #if ORTHANC_PLUGINS_ENABLED == 1 if (plugins_ != NULL) { - plugins_->GetErrorDictionary().LogError(exception); + plugins_->GetErrorDictionary().LogError(exception.GetErrorCode(), true); isPlugin = true; } #endif diff -r 9f34ebfaf2c9 -r 2e692c83e2f3 Plugins/Engine/OrthancPluginDatabase.cpp --- a/Plugins/Engine/OrthancPluginDatabase.cpp Fri Sep 25 16:47:05 2015 +0200 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Fri Sep 25 17:29:39 2015 +0200 @@ -194,11 +194,13 @@ OrthancPluginDatabase::OrthancPluginDatabase(SharedLibrary& library, + PluginsErrorDictionary& errorDictionary, const OrthancPluginDatabaseBackend& backend, const OrthancPluginDatabaseExtensions* extensions, size_t extensionsSize, void *payload) : library_(library), + errorDictionary_(errorDictionary), type_(_OrthancPluginDatabaseAnswerType_None), backend_(backend), payload_(payload), @@ -236,6 +238,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -248,6 +251,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -259,6 +263,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -270,6 +275,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -284,6 +290,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -298,6 +305,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -310,6 +318,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -321,6 +330,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -357,6 +367,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -379,6 +390,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -432,6 +444,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -446,6 +459,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -462,6 +476,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -483,6 +498,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -500,6 +516,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -517,6 +534,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -532,6 +550,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -546,6 +565,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -566,6 +586,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -581,6 +602,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -596,6 +618,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -611,6 +634,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -626,6 +650,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -641,6 +666,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -657,6 +683,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -688,6 +715,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -724,6 +752,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -746,6 +775,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -762,6 +792,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -792,6 +823,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -814,6 +846,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -830,6 +863,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -847,6 +881,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -863,6 +898,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -880,6 +916,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -909,6 +946,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -925,6 +963,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -940,6 +979,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -967,6 +1007,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -981,6 +1022,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -993,6 +1035,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -1003,12 +1046,15 @@ private: const OrthancPluginDatabaseBackend& backend_; void* payload_; + PluginsErrorDictionary& errorDictionary_; public: Transaction(const OrthancPluginDatabaseBackend& backend, - void* payload) : + void* payload, + PluginsErrorDictionary& errorDictionary) : backend_(backend), - payload_(payload) + payload_(payload), + errorDictionary_(errorDictionary) { } @@ -1018,6 +1064,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -1028,6 +1075,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -1038,6 +1086,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -1046,7 +1095,7 @@ SQLite::ITransaction* OrthancPluginDatabase::StartTransaction() { - return new Transaction(backend_, payload_); + return new Transaction(backend_, payload_, errorDictionary_); } @@ -1093,6 +1142,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -1119,6 +1169,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } diff -r 9f34ebfaf2c9 -r 2e692c83e2f3 Plugins/Engine/OrthancPluginDatabase.h --- a/Plugins/Engine/OrthancPluginDatabase.h Fri Sep 25 16:47:05 2015 +0200 +++ b/Plugins/Engine/OrthancPluginDatabase.h Fri Sep 25 17:29:39 2015 +0200 @@ -36,6 +36,7 @@ #include "../../OrthancServer/IDatabaseWrapper.h" #include "../Include/orthanc/OrthancCDatabasePlugin.h" +#include "PluginsErrorDictionary.h" #include "SharedLibrary.h" namespace Orthanc @@ -48,6 +49,7 @@ typedef std::pair AnswerResource; SharedLibrary& library_; + PluginsErrorDictionary& errorDictionary_; _OrthancPluginDatabaseAnswerType type_; OrthancPluginDatabaseBackend backend_; OrthancPluginDatabaseExtensions extensions_; @@ -82,6 +84,7 @@ public: OrthancPluginDatabase(SharedLibrary& library, + PluginsErrorDictionary& errorDictionary, const OrthancPluginDatabaseBackend& backend, const OrthancPluginDatabaseExtensions* extensions, size_t extensionsSize, diff -r 9f34ebfaf2c9 -r 2e692c83e2f3 Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Fri Sep 25 16:47:05 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Fri Sep 25 17:29:39 2015 +0200 @@ -66,6 +66,7 @@ { private: _OrthancPluginRegisterStorageArea callbacks_; + PluginsErrorDictionary& errorDictionary_; void Free(void* buffer) const { @@ -76,7 +77,10 @@ } public: - PluginStorageArea(const _OrthancPluginRegisterStorageArea& callbacks) : callbacks_(callbacks) + PluginStorageArea(const _OrthancPluginRegisterStorageArea& callbacks, + PluginsErrorDictionary& errorDictionary) : + callbacks_(callbacks), + errorDictionary_(errorDictionary) { } @@ -91,6 +95,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -108,6 +113,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } @@ -138,6 +144,7 @@ if (error != OrthancPluginErrorCode_Success) { + errorDictionary_.LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -149,12 +156,15 @@ private: SharedLibrary& sharedLibrary_; _OrthancPluginRegisterStorageArea callbacks_; + PluginsErrorDictionary& errorDictionary_; public: StorageAreaFactory(SharedLibrary& sharedLibrary, - const _OrthancPluginRegisterStorageArea& callbacks) : + const _OrthancPluginRegisterStorageArea& callbacks, + PluginsErrorDictionary& errorDictionary) : sharedLibrary_(sharedLibrary), - callbacks_(callbacks) + callbacks_(callbacks), + errorDictionary_(errorDictionary) { } @@ -165,7 +175,7 @@ IStorageArea* Create() const { - return new PluginStorageArea(callbacks_); + return new PluginStorageArea(callbacks_, errorDictionary_); } }; } @@ -464,6 +474,7 @@ } else { + GetErrorDictionary().LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -485,6 +496,7 @@ if (error != OrthancPluginErrorCode_Success) { + GetErrorDictionary().LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -507,6 +519,7 @@ if (error != OrthancPluginErrorCode_Success) { + GetErrorDictionary().LogError(error, true); throw OrthancException(static_cast(error)); } } @@ -1378,7 +1391,7 @@ if (pimpl_->storageArea_.get() == NULL) { - pimpl_->storageArea_.reset(new StorageAreaFactory(plugin, p)); + pimpl_->storageArea_.reset(new StorageAreaFactory(plugin, p, GetErrorDictionary())); } else { @@ -1457,7 +1470,8 @@ if (pimpl_->database_.get() == NULL) { - pimpl_->database_.reset(new OrthancPluginDatabase(plugin, *p.backend, NULL, 0, p.payload)); + pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), + *p.backend, NULL, 0, p.payload)); } else { @@ -1478,7 +1492,8 @@ if (pimpl_->database_.get() == NULL) { - pimpl_->database_.reset(new OrthancPluginDatabase(plugin, *p.backend, p.extensions, + pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), + *p.backend, p.extensions, p.extensionsSize, p.payload)); } else diff -r 9f34ebfaf2c9 -r 2e692c83e2f3 Plugins/Engine/PluginsErrorDictionary.cpp --- a/Plugins/Engine/PluginsErrorDictionary.cpp Fri Sep 25 16:47:05 2015 +0200 +++ b/Plugins/Engine/PluginsErrorDictionary.cpp Fri Sep 25 17:29:39 2015 +0200 @@ -88,12 +88,13 @@ } - void PluginsErrorDictionary::LogError(const OrthancException& exception) + void PluginsErrorDictionary::LogError(ErrorCode code, + bool ignoreBuiltinErrors) { - if (exception.GetErrorCode() >= ErrorCode_START_PLUGINS) + if (code >= ErrorCode_START_PLUGINS) { boost::mutex::scoped_lock lock(mutex_); - Errors::const_iterator error = errors_.find(static_cast(exception.GetErrorCode())); + Errors::const_iterator error = errors_.find(static_cast(code)); if (error != errors_.end()) { @@ -104,7 +105,11 @@ } } - LOG(ERROR) << "Exception inside the plugin engine: " << exception.What(); + if (!ignoreBuiltinErrors) + { + LOG(ERROR) << "Exception inside the plugin engine: " + << EnumerationToString(code); + } } diff -r 9f34ebfaf2c9 -r 2e692c83e2f3 Plugins/Engine/PluginsErrorDictionary.h --- a/Plugins/Engine/PluginsErrorDictionary.h Fri Sep 25 16:47:05 2015 +0200 +++ b/Plugins/Engine/PluginsErrorDictionary.h Fri Sep 25 17:29:39 2015 +0200 @@ -74,7 +74,14 @@ uint16_t httpStatus, const char* message); - void LogError(const OrthancException& exception); + void LogError(ErrorCode code, + bool ignoreBuiltinErrors); + + void LogError(OrthancPluginErrorCode code, + bool ignoreBuiltinErrors) + { + LogError(static_cast(code), ignoreBuiltinErrors); + } bool Format(Json::Value& message, /* out */ HttpStatus& httpStatus, /* out */ diff -r 9f34ebfaf2c9 -r 2e692c83e2f3 Plugins/Samples/Basic/Plugin.c --- a/Plugins/Samples/Basic/Plugin.c Fri Sep 25 16:47:05 2015 +0200 +++ b/Plugins/Samples/Basic/Plugin.c Fri Sep 25 17:29:39 2015 +0200 @@ -25,7 +25,7 @@ static OrthancPluginContext* context = NULL; -static OrthancPluginErrorCode c1; +static OrthancPluginErrorCode customError; ORTHANC_PLUGINS_API int32_t Callback1(OrthancPluginRestOutput* output, @@ -216,8 +216,6 @@ const char* url, const OrthancPluginHttpRequest* request) { - return c1; - const char* pathLocator = "\"Path\" : \""; char info[1024]; char *id, *eos; @@ -405,7 +403,7 @@ sprintf(info, "[ \"STORESCP\", \"localhost\", 2000 ]"); OrthancPluginRestApiPut(context, &tmp, "/modalities/demo", info, strlen(info)); - c1 = OrthancPluginRegisterErrorCode(context, 4, 402, "Hello world"); + customError = OrthancPluginRegisterErrorCode(context, 4, 402, "Hello world"); return 0; }