Mercurial > hg > orthanc
changeset 1643:87c77b9b3679
provision for error codes in plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Sep 2015 14:42:20 +0200 |
parents | 0669d05b6de1 |
children | 939b921b2c81 |
files | Core/Enumerations.cpp Core/Enumerations.h Core/OrthancException.h Plugins/Engine/OrthancPlugins.cpp Plugins/Engine/PluginsEnumerations.cpp Plugins/Include/orthanc/OrthancCPlugin.h Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Plugins/Samples/StorageArea/Plugin.cpp Resources/ErrorCodes.json |
diffstat | 9 files changed, 122 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Enumerations.cpp Wed Sep 23 13:39:00 2015 +0200 +++ b/Core/Enumerations.cpp Wed Sep 23 14:42:20 2015 +0200 @@ -142,6 +142,12 @@ case ErrorCode_BadFont: return "Badly formatted font file"; + case ErrorCode_DatabasePlugin: + return "The plugin implementing a custom database back-end does not fulfill the proper interface"; + + case ErrorCode_StorageAreaPlugin: + return "Error in the plugin implementing a custom storage area"; + case ErrorCode_SQLiteNotOpened: return "SQLite: The database is not opened"; @@ -304,8 +310,8 @@ case ErrorCode_DatabaseBackendAlreadyRegistered: return "Another plugin has already registered a custom database back-end"; - case ErrorCode_DatabasePlugin: - return "The plugin implementing a custom database back-end does not fulfill the proper interface"; + case ErrorCode_DatabaseNotInitialized: + return "Plugin trying to call the database during its initialization"; default: return "Unknown error code";
--- a/Core/Enumerations.h Wed Sep 23 13:39:00 2015 +0200 +++ b/Core/Enumerations.h Wed Sep 23 14:42:20 2015 +0200 @@ -77,6 +77,8 @@ ErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */, ErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */, ErrorCode_BadFont = 30 /*!< Badly formatted font file */, + ErrorCode_DatabasePlugin = 31 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */, + ErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */, ErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */, ErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */, ErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */, @@ -131,7 +133,7 @@ ErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */, ErrorCode_StorageAreaAlreadyRegistered = 2036 /*!< Another plugin has already registered a custom storage area */, ErrorCode_DatabaseBackendAlreadyRegistered = 2037 /*!< Another plugin has already registered a custom database back-end */, - ErrorCode_DatabasePlugin = 2038 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */ + ErrorCode_DatabaseNotInitialized = 2038 /*!< Plugin trying to call the database during its initialization */ }; enum LogLevel
--- a/Core/OrthancException.h Wed Sep 23 13:39:00 2015 +0200 +++ b/Core/OrthancException.h Wed Sep 23 14:42:20 2015 +0200 @@ -32,6 +32,7 @@ #pragma once +#include <stdint.h> #include <string> #include "Enumerations.h" @@ -40,23 +41,41 @@ class OrthancException { protected: - ErrorCode errorCode_; + ErrorCode errorCode_; HttpStatus httpStatus_; + int32_t pluginCode_; + + OrthancException(ErrorCode errorCode, + HttpStatus httpStatus, + int32_t pluginCode) : + errorCode_(errorCode), + httpStatus_(httpStatus), + pluginCode_(0) + { + } public: OrthancException(ErrorCode errorCode) : errorCode_(errorCode), - httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)) + httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)), + pluginCode_(0) { } OrthancException(ErrorCode errorCode, HttpStatus httpStatus) : errorCode_(errorCode), - httpStatus_(httpStatus) + httpStatus_(httpStatus), + pluginCode_(0) { } + static OrthancException GetPluginException(int32_t pluginCode, + HttpStatus httpStatus) + { + return OrthancException(ErrorCode_Plugin, httpStatus, pluginCode); + } + ErrorCode GetErrorCode() const { return errorCode_; @@ -67,6 +86,11 @@ return httpStatus_; } + int32_t GetPluginErrorCode() const + { + return pluginCode_; + } + const char* What() const { return EnumerationToString(errorCode_);
--- a/Plugins/Engine/OrthancPlugins.cpp Wed Sep 23 13:39:00 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Wed Sep 23 14:42:20 2015 +0200 @@ -118,7 +118,7 @@ catch (...) { Free(buffer); - throw; + throw OrthancException(ErrorCode_NotEnoughMemory); } if (size > 0) @@ -743,8 +743,7 @@ { if (!pimpl_->context_) { - LOG(ERROR) << "Plugin trying to call the database during its initialization"; - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(ErrorCode_DatabaseNotInitialized); } }
--- a/Plugins/Engine/PluginsEnumerations.cpp Wed Sep 23 13:39:00 2015 +0200 +++ b/Plugins/Engine/PluginsEnumerations.cpp Wed Sep 23 14:42:20 2015 +0200 @@ -144,6 +144,12 @@ case OrthancPluginErrorCode_BadFont: return ErrorCode_BadFont; + case OrthancPluginErrorCode_DatabasePlugin: + return ErrorCode_DatabasePlugin; + + case OrthancPluginErrorCode_StorageAreaPlugin: + return ErrorCode_StorageAreaPlugin; + case OrthancPluginErrorCode_SQLiteNotOpened: return ErrorCode_SQLiteNotOpened; @@ -306,8 +312,8 @@ case OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered: return ErrorCode_DatabaseBackendAlreadyRegistered; - case OrthancPluginErrorCode_DatabasePlugin: - return ErrorCode_DatabasePlugin; + case OrthancPluginErrorCode_DatabaseNotInitialized: + return ErrorCode_DatabaseNotInitialized; default: return ErrorCode_Plugin;
--- a/Plugins/Include/orthanc/OrthancCPlugin.h Wed Sep 23 13:39:00 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Wed Sep 23 14:42:20 2015 +0200 @@ -210,6 +210,8 @@ OrthancPluginErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */, OrthancPluginErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */, OrthancPluginErrorCode_BadFont = 30 /*!< Badly formatted font file */, + OrthancPluginErrorCode_DatabasePlugin = 31 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */, + OrthancPluginErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */, OrthancPluginErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */, OrthancPluginErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */, OrthancPluginErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */, @@ -264,7 +266,7 @@ OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */, OrthancPluginErrorCode_StorageAreaAlreadyRegistered = 2036 /*!< Another plugin has already registered a custom storage area */, OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered = 2037 /*!< Another plugin has already registered a custom database back-end */, - OrthancPluginErrorCode_DatabasePlugin = 2038 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */, + OrthancPluginErrorCode_DatabaseNotInitialized = 2038 /*!< Plugin trying to call the database during its initialization */, _OrthancPluginErrorCode_INTERNAL = 0x7fffffff } OrthancPluginErrorCode;
--- a/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Wed Sep 23 13:39:00 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Wed Sep 23 14:42:20 2015 +0200 @@ -71,7 +71,7 @@ OrthancPluginErrorCode code_; public: - DatabaseException() : code_(OrthancPluginErrorCode_Plugin) + DatabaseException() : code_(OrthancPluginErrorCode_DatabasePlugin) { } @@ -501,7 +501,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -525,7 +525,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -547,7 +547,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -569,7 +569,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -594,7 +594,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -618,7 +618,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -642,7 +642,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -665,7 +665,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -699,7 +699,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -735,7 +735,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -768,7 +768,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -801,7 +801,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -835,7 +835,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -867,7 +867,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -890,7 +890,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -913,7 +913,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -937,7 +937,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -965,7 +965,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -989,7 +989,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1013,7 +1013,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1036,7 +1036,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1059,7 +1059,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1083,7 +1083,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1107,7 +1107,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1141,7 +1141,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1175,7 +1175,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1198,7 +1198,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1221,7 +1221,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1246,7 +1246,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1277,7 +1277,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1310,7 +1310,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1343,7 +1343,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1374,7 +1374,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1404,7 +1404,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1436,7 +1436,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1465,7 +1465,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1495,7 +1495,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1519,7 +1519,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1543,7 +1543,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1567,7 +1567,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1592,7 +1592,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1616,7 +1616,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1638,7 +1638,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1660,7 +1660,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1682,7 +1682,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1704,7 +1704,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1726,7 +1726,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1748,7 +1748,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) { @@ -1771,7 +1771,7 @@ catch (std::runtime_error& e) { LogError(backend, e); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_DatabasePlugin; } catch (DatabaseException& e) {
--- a/Plugins/Samples/StorageArea/Plugin.cpp Wed Sep 23 13:39:00 2015 +0200 +++ b/Plugins/Samples/StorageArea/Plugin.cpp Wed Sep 23 14:42:20 2015 +0200 @@ -43,13 +43,13 @@ FILE* fp = fopen(path.c_str(), "wb"); if (!fp) { - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_StorageAreaPlugin; } bool ok = fwrite(content, size, 1, fp) == 1; fclose(fp); - return ok ? OrthancPluginErrorCode_Success : OrthancPluginErrorCode_Plugin; + return ok ? OrthancPluginErrorCode_Success : OrthancPluginErrorCode_StorageAreaPlugin; } @@ -63,13 +63,13 @@ FILE* fp = fopen(path.c_str(), "rb"); if (!fp) { - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_StorageAreaPlugin; } if (fseek(fp, 0, SEEK_END) < 0) { fclose(fp); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_StorageAreaPlugin; } *size = ftell(fp); @@ -77,7 +77,7 @@ if (fseek(fp, 0, SEEK_SET) < 0) { fclose(fp); - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_StorageAreaPlugin; } bool ok = true; @@ -98,7 +98,7 @@ fclose(fp); - return ok ? OrthancPluginErrorCode_Success : OrthancPluginErrorCode_Plugin; + return ok ? OrthancPluginErrorCode_Success : OrthancPluginErrorCode_StorageAreaPlugin; } @@ -113,7 +113,7 @@ } else { - return OrthancPluginErrorCode_Plugin; + return OrthancPluginErrorCode_StorageAreaPlugin; } }
--- a/Resources/ErrorCodes.json Wed Sep 23 13:39:00 2015 +0200 +++ b/Resources/ErrorCodes.json Wed Sep 23 14:42:20 2015 +0200 @@ -175,7 +175,16 @@ "Name": "BadFont", "Description": "Badly formatted font file" }, - + { + "Code": 31, + "Name": "DatabasePlugin", + "Description": "The plugin implementing a custom database back-end does not fulfill the proper interface" + }, + { + "Code": 32, + "Name": "StorageAreaPlugin", + "Description": "Error in the plugin implementing a custom storage area" + }, @@ -478,10 +487,10 @@ "Code": 2037, "Name": "DatabaseBackendAlreadyRegistered", "Description": "Another plugin has already registered a custom database back-end" - }, + }, { - "Code": 2038, - "Name": "DatabasePlugin", - "Description": "The plugin implementing a custom database back-end does not fulfill the proper interface" + "Code": 2038, + "Name": "DatabaseNotInitialized", + "Description": "Plugin trying to call the database during its initialization" } ]