# HG changeset patch # User Sebastien Jodogne # Date 1440517970 -7200 # Node ID 9ea3d082b064632e28c72a00ad0998c6c42215d4 # Parent bd1889029cbb75f69b6dcef3b04fc52993796b4b got rid of custom exceptions diff -r bd1889029cbb -r 9ea3d082b064 Core/Enumerations.cpp --- a/Core/Enumerations.cpp Tue Aug 25 17:39:38 2015 +0200 +++ b/Core/Enumerations.cpp Tue Aug 25 17:52:50 2015 +0200 @@ -46,9 +46,6 @@ { switch (error) { - case ErrorCode_Custom: - return "Custom error, see the attached error message"; - case ErrorCode_InternalError: return "Internal error"; @@ -271,6 +268,27 @@ case ErrorCode_BadJobOrdering: return "Bad ordering of filters in a job"; + case ErrorCode_JsonToLuaTable: + return "Cannot convert the given JSON object to a Lua table"; + + case ErrorCode_CannotCreateLua: + return "Cannot create the Lua context"; + + case ErrorCode_CannotExecuteLua: + return "Cannot execute a Lua command"; + + case ErrorCode_LuaAlreadyExecuted: + return "Arguments cannot be pushed after the Lua function is executed"; + + case ErrorCode_LuaBadOutput: + return "The Lua function does not give the expected number of outputs"; + + case ErrorCode_NotLuaPredicate: + return "The Lua function is not a predicate (only true/false outputs allowed)"; + + case ErrorCode_LuaReturnsNoString: + return "The Lua function does not return a string"; + default: return "Unknown error code"; } diff -r bd1889029cbb -r 9ea3d082b064 Core/Enumerations.h --- a/Core/Enumerations.h Tue Aug 25 17:39:38 2015 +0200 +++ b/Core/Enumerations.h Tue Aug 25 17:52:50 2015 +0200 @@ -45,7 +45,6 @@ // "Resources/GenerateErrorCodes.py" enum ErrorCode { - ErrorCode_Custom = -2 /*!< Custom error, see the attached error message */, ErrorCode_InternalError = -1 /*!< Internal error */, ErrorCode_Success = 0 /*!< Success */, ErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */, @@ -119,7 +118,14 @@ ErrorCode_CreateDicomParentIsInstance = 2025 /*!< Trying to attach a new DICOM instance to an instance (must be a series, study or patient) */, ErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */, ErrorCode_UnknownModality = 2027 /*!< Unknown modality */, - ErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */ + ErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */, + ErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */, + ErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */, + ErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */, + ErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */, + ErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */, + ErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */, + ErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */ }; enum LogLevel diff -r bd1889029cbb -r 9ea3d082b064 Core/Lua/LuaContext.cpp --- a/Core/Lua/LuaContext.cpp Tue Aug 25 17:39:38 2015 +0200 +++ b/Core/Lua/LuaContext.cpp Tue Aug 25 17:52:50 2015 +0200 @@ -34,6 +34,7 @@ #include "LuaContext.h" #include "../Logging.h" +#include "../OrthancException.h" #include #include @@ -369,7 +370,7 @@ } else { - throw LuaException("Unsupported JSON conversion"); + throw OrthancException(ErrorCode_JsonToLuaTable); } } @@ -484,7 +485,7 @@ lua_ = luaL_newstate(); if (!lua_) { - throw LuaException("Unable to create the Lua context"); + throw OrthancException(ErrorCode_CannotCreateLua); } luaL_openlibs(lua_); @@ -521,7 +522,7 @@ std::string description(lua_tostring(lua_, -1)); lua_pop(lua_, 1); /* pop error message from the stack */ LOG(ERROR) << "Error while executing Lua script: " << description; - throw LuaException(description); + throw OrthancException(ErrorCode_CannotExecuteLua); } if (output != NULL) diff -r bd1889029cbb -r 9ea3d082b064 Core/Lua/LuaContext.h --- a/Core/Lua/LuaContext.h Tue Aug 25 17:39:38 2015 +0200 +++ b/Core/Lua/LuaContext.h Tue Aug 25 17:52:50 2015 +0200 @@ -32,7 +32,6 @@ #pragma once -#include "LuaException.h" #include "../HttpClient.h" extern "C" diff -r bd1889029cbb -r 9ea3d082b064 Core/Lua/LuaException.h --- a/Core/Lua/LuaException.h Tue Aug 25 17:39:38 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - **/ - - -#pragma once - -#include "../OrthancException.h" - -namespace Orthanc -{ - class LuaException : public OrthancException - { - public: - LuaException(const char* explanation) : - OrthancException(explanation) - { - } - - LuaException(const std::string& explanation) : - OrthancException(explanation) - { - } - }; -} diff -r bd1889029cbb -r 9ea3d082b064 Core/Lua/LuaFunctionCall.cpp --- a/Core/Lua/LuaFunctionCall.cpp Tue Aug 25 17:39:38 2015 +0200 +++ b/Core/Lua/LuaFunctionCall.cpp Tue Aug 25 17:52:50 2015 +0200 @@ -33,6 +33,9 @@ #include "../PrecompiledHeaders.h" #include "LuaFunctionCall.h" +#include "../OrthancException.h" +#include "../Logging.h" + #include #include #include @@ -43,7 +46,7 @@ { if (isExecuted_) { - throw LuaException("Arguments cannot be pushed after the function is executed"); + throw OrthancException(ErrorCode_LuaAlreadyExecuted); } } @@ -101,12 +104,14 @@ std::string description(lua_tostring(context_.lua_, -1)); lua_pop(context_.lua_, 1); /* pop error message from the stack */ - throw LuaException(description); + LOG(ERROR) << description; + + throw OrthancException(ErrorCode_CannotExecuteLua); } if (lua_gettop(context_.lua_) < numOutputs) { - throw LuaException("The function does not give the expected number of outputs"); + throw OrthancException(ErrorCode_LuaBadOutput); } isExecuted_ = true; @@ -118,7 +123,7 @@ if (!lua_isboolean(context_.lua_, 1)) { - throw LuaException("The function is not a predicate (only true/false outputs allowed)"); + throw OrthancException(ErrorCode_NotLuaPredicate); } return lua_toboolean(context_.lua_, 1) != 0; @@ -143,7 +148,7 @@ } else { - throw LuaException("The function does not return a string"); + throw OrthancException(ErrorCode_LuaReturnsNoString); } } } diff -r bd1889029cbb -r 9ea3d082b064 Core/OrthancException.h --- a/Core/OrthancException.h Tue Aug 25 17:39:38 2015 +0200 +++ b/Core/OrthancException.h Tue Aug 25 17:52:50 2015 +0200 @@ -42,14 +42,6 @@ protected: ErrorCode errorCode_; HttpStatus httpStatus_; - std::string custom_; - - OrthancException(const std::string& custom) : - errorCode_(ErrorCode_Custom), - httpStatus_(HttpStatus_500_InternalServerError), - custom_(custom) - { - } public: OrthancException(ErrorCode errorCode) : @@ -77,14 +69,7 @@ const char* What() const { - if (errorCode_ == ErrorCode_Custom) - { - return custom_.c_str(); - } - else - { - return EnumerationToString(errorCode_); - } + return EnumerationToString(errorCode_); } }; } diff -r bd1889029cbb -r 9ea3d082b064 Plugins/Include/orthanc/OrthancCPlugin.h --- a/Plugins/Include/orthanc/OrthancCPlugin.h Tue Aug 25 17:39:38 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Tue Aug 25 17:52:50 2015 +0200 @@ -160,7 +160,6 @@ **/ typedef enum { - OrthancPluginErrorCode_Custom = -2 /*!< Custom error, see the attached error message */, OrthancPluginErrorCode_InternalError = -1 /*!< Internal error */, OrthancPluginErrorCode_Success = 0 /*!< Success */, OrthancPluginErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */, @@ -235,6 +234,13 @@ OrthancPluginErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */, OrthancPluginErrorCode_UnknownModality = 2027 /*!< Unknown modality */, OrthancPluginErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */, + OrthancPluginErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */, + OrthancPluginErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */, + OrthancPluginErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */, + OrthancPluginErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */, + OrthancPluginErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */, + OrthancPluginErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */, + OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */, _OrthancPluginErrorCode_INTERNAL = 0x7fffffff } OrthancPluginErrorCode; diff -r bd1889029cbb -r 9ea3d082b064 Resources/ErrorCodes.json --- a/Resources/ErrorCodes.json Tue Aug 25 17:39:38 2015 +0200 +++ b/Resources/ErrorCodes.json Tue Aug 25 17:52:50 2015 +0200 @@ -2,11 +2,6 @@ /** Generic error codes **/ { - "Code": -2, - "Name": "Custom", - "Description": "Custom error, see the attached error message" - }, - { "Code": -1, "Name": "InternalError", "Description": "Internal error" @@ -423,5 +418,40 @@ "Code": 2028, "Name": "BadJobOrdering", "Description": "Bad ordering of filters in a job" + }, + { + "Code": 2029, + "Name": "JsonToLuaTable", + "Description": "Cannot convert the given JSON object to a Lua table" + }, + { + "Code": 2030, + "Name": "CannotCreateLua", + "Description": "Cannot create the Lua context" + }, + { + "Code": 2031, + "Name": "CannotExecuteLua", + "Description": "Cannot execute a Lua command" + }, + { + "Code": 2032, + "Name": "LuaAlreadyExecuted", + "Description": "Arguments cannot be pushed after the Lua function is executed" + }, + { + "Code": 2033, + "Name": "LuaBadOutput", + "Description": "The Lua function does not give the expected number of outputs" + }, + { + "Code": 2034, + "Name": "NotLuaPredicate", + "Description": "The Lua function is not a predicate (only true/false outputs allowed)" + }, + { + "Code": 2035, + "Name": "LuaReturnsNoString", + "Description": "The Lua function does not return a string" } ] diff -r bd1889029cbb -r 9ea3d082b064 UnitTestsSources/LuaTests.cpp --- a/UnitTestsSources/LuaTests.cpp Tue Aug 25 17:39:38 2015 +0200 +++ b/UnitTestsSources/LuaTests.cpp Tue Aug 25 17:52:50 2015 +0200 @@ -33,6 +33,7 @@ #include "PrecompiledHeadersUnitTests.h" #include "gtest/gtest.h" +#include "../Core/OrthancException.h" #include "../Core/Toolbox.h" #include "../Core/Lua/LuaFunctionCall.h" @@ -79,7 +80,7 @@ { Orthanc::LuaFunctionCall f(lua, "f"); f.PushJson(o); - ASSERT_THROW(f.ExecutePredicate(), Orthanc::LuaException); + ASSERT_THROW(f.ExecutePredicate(), Orthanc::OrthancException); } o["bool"] = false; diff -r bd1889029cbb -r 9ea3d082b064 UnitTestsSources/MultiThreadingTests.cpp --- a/UnitTestsSources/MultiThreadingTests.cpp Tue Aug 25 17:39:38 2015 +0200 +++ b/UnitTestsSources/MultiThreadingTests.cpp Tue Aug 25 17:52:50 2015 +0200 @@ -96,7 +96,7 @@ SharedMessageQueue q; q.Enqueue(new DynamicInteger(10, s)); q.Enqueue(new DynamicInteger(20, s)); - throw OrthancException(ErrorCode_Custom); + throw OrthancException(ErrorCode_InternalError); } catch (OrthancException&) {