From 15358c6e9561267fec53a6e8180fd598a00baeef Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 1 Oct 2014 16:01:47 +0100 Subject: [PATCH] Fix missing error messages (part 2) refs #7331 --- lib/base/CMakeLists.txt | 2 +- lib/{config => base}/configerror.cpp | 11 +++++++++-- lib/{config => base}/configerror.hpp | 12 +++++++++--- lib/base/dynamictype.cpp | 3 ++- lib/base/exception.cpp | 15 --------------- lib/base/exception.hpp | 13 ++----------- lib/config/CMakeLists.txt | 2 +- lib/config/aexpression.cpp | 2 +- lib/config/config_parser.yy | 2 +- lib/config/configitem.cpp | 2 +- 10 files changed, 27 insertions(+), 37 deletions(-) rename lib/{config => base}/configerror.cpp (89%) rename lib/{config => base}/configerror.hpp (88%) diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index dedfb1587..3707587ef 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -23,7 +23,7 @@ mkclass_target(streamlogger.ti streamlogger.thpp) mkclass_target(sysloglogger.ti sysloglogger.thpp) set(base_SOURCES - application.cpp application.thpp array.cpp context.cpp + application.cpp application.thpp array.cpp configerror.cpp context.cpp convert.cpp debuginfo.cpp dictionary.cpp dynamicobject.cpp dynamicobject.thpp dynamictype.cpp exception.cpp fifo.cpp filelogger.cpp filelogger.thpp logger.cpp logger.thpp netstring.cpp networkstream.cpp object.cpp objectlock.cpp process.cpp diff --git a/lib/config/configerror.cpp b/lib/base/configerror.cpp similarity index 89% rename from lib/config/configerror.cpp rename to lib/base/configerror.cpp index 453cae65e..3c43f7fd8 100644 --- a/lib/config/configerror.cpp +++ b/lib/base/configerror.cpp @@ -17,12 +17,19 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "config/configerror.hpp" +#include "base/configerror.hpp" #include using namespace icinga; ConfigError::ConfigError(const String& message) - : user_error(message) + : m_Message(message) { } +ConfigError::~ConfigError(void) throw() +{ } + +const char *ConfigError::what(void) const throw() +{ + return m_Message.CStr(); +} diff --git a/lib/config/configerror.hpp b/lib/base/configerror.hpp similarity index 88% rename from lib/config/configerror.hpp rename to lib/base/configerror.hpp index f389b9b11..ed6b4f6ef 100644 --- a/lib/config/configerror.hpp +++ b/lib/base/configerror.hpp @@ -20,7 +20,7 @@ #ifndef CONFIGERROR_H #define CONFIGERROR_H -#include "config/i2-config.hpp" +#include "base/i2-base.hpp" #include "base/debuginfo.hpp" #include "base/exception.hpp" @@ -28,12 +28,18 @@ namespace icinga { /* - * @ingroup config + * @ingroup base */ -class I2_CONFIG_API ConfigError : virtual public user_error +class I2_BASE_API ConfigError : virtual public user_error { public: ConfigError(const String& message); + ~ConfigError(void) throw(); + + virtual const char *what(void) const throw(); + +private: + String m_Message; }; } diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index 57a09639a..067035360 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -22,6 +22,7 @@ #include "base/debug.hpp" #include "base/objectlock.hpp" #include "base/convert.hpp" +#include "base/configerror.hpp" using namespace icinga; @@ -100,7 +101,7 @@ void DynamicType::RegisterObject(const DynamicObject::Ptr& object) if (it->second == object) return; - BOOST_THROW_EXCEPTION(user_error("An object with type '" + m_Name + "' and name '" + name + "' already exists (" + + BOOST_THROW_EXCEPTION(ConfigError("An object with type '" + m_Name + "' and name '" + name + "' already exists (" + Convert::ToString(it->second->GetDebugInfo()) + "), new declaration: " + Convert::ToString(object->GetDebugInfo())) << errinfo_debuginfo(object->GetDebugInfo())); } diff --git a/lib/base/exception.cpp b/lib/base/exception.cpp index f809dbe3d..a2a9c6a9b 100644 --- a/lib/base/exception.cpp +++ b/lib/base/exception.cpp @@ -153,18 +153,3 @@ String icinga::DiagnosticInformation(boost::exception_ptr eptr) return boost::diagnostic_information(eptr); } -user_error::user_error(void) -{ } - -user_error::user_error(const String& message) - : m_Message(message) -{ } - -user_error::~user_error(void) throw() -{ } - -const char *user_error::what(void) const throw() -{ - return m_Message.CStr(); -} - diff --git a/lib/base/exception.hpp b/lib/base/exception.hpp index c47ce34d7..ead065388 100644 --- a/lib/base/exception.hpp +++ b/lib/base/exception.hpp @@ -38,17 +38,8 @@ namespace icinga { -class I2_BASE_API user_error : virtual public std::exception, virtual public boost::exception { -public: - user_error(void); - user_error(const String& message); - ~user_error(void) throw(); - - const char *what(void) const throw(); - -private: - String m_Message; -}; +class I2_BASE_API user_error : virtual public std::exception, virtual public boost::exception +{ }; I2_BASE_API StackTrace *GetLastExceptionStack(void); I2_BASE_API void SetLastExceptionStack(const StackTrace& trace); diff --git a/lib/config/CMakeLists.txt b/lib/config/CMakeLists.txt index db582cbe3..300df7527 100644 --- a/lib/config/CMakeLists.txt +++ b/lib/config/CMakeLists.txt @@ -32,7 +32,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) set(config_SOURCES aexpression.cpp applyrule.cpp base-type.conf base-type.cpp - configcompilercontext.cpp configcompiler.cpp configerror.cpp configitembuilder.cpp + configcompilercontext.cpp configcompiler.cpp configitembuilder.cpp configitem.cpp ${FLEX_config_lexer_OUTPUTS} ${BISON_config_parser_OUTPUTS} configtype.cpp objectrule.cpp typerule.cpp typerulelist.cpp ) diff --git a/lib/config/aexpression.cpp b/lib/config/aexpression.cpp index 5269d5928..8e3f34625 100644 --- a/lib/config/aexpression.cpp +++ b/lib/config/aexpression.cpp @@ -18,7 +18,6 @@ ******************************************************************************/ #include "config/aexpression.hpp" -#include "config/configerror.hpp" #include "config/configitem.hpp" #include "config/configitembuilder.hpp" #include "config/applyrule.hpp" @@ -31,6 +30,7 @@ #include "base/objectlock.hpp" #include "base/object.hpp" #include "base/logger_fwd.hpp" +#include "base/configerror.hpp" #include #include #include diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index 1fe2b756e..d31700a18 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -25,7 +25,6 @@ #include "config/configtype.hpp" #include "config/configcompiler.hpp" #include "config/configcompilercontext.hpp" -#include "config/configerror.hpp" #include "config/typerule.hpp" #include "config/typerulelist.hpp" #include "config/aexpression.hpp" @@ -38,6 +37,7 @@ #include "base/scriptvariable.hpp" #include "base/exception.hpp" #include "base/dynamictype.hpp" +#include "base/configerror.hpp" #include #include #include diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index ad5ae174c..c786c9d82 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -22,7 +22,6 @@ #include "config/applyrule.hpp" #include "config/objectrule.hpp" #include "config/configtype.hpp" -#include "config/configerror.hpp" #include "base/application.hpp" #include "base/dynamictype.hpp" #include "base/objectlock.hpp" @@ -33,6 +32,7 @@ #include "base/exception.hpp" #include "base/stdiostream.hpp" #include "base/netstring.hpp" +#include "base/configerror.hpp" #include #include #include