From 2720333d6e82d442ef61609dea201a54f4b0a805 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 10 Dec 2014 15:06:09 +0100 Subject: [PATCH] Fix missing location information for included files fixes #7927 --- lib/base/CMakeLists.txt | 4 +-- lib/base/debuginfo.cpp | 8 ----- lib/base/debuginfo.hpp | 5 ---- lib/base/dynamictype.cpp | 8 ++--- lib/base/{configerror.cpp => scripterror.cpp} | 18 ++++++++--- lib/base/{configerror.hpp => scripterror.hpp} | 16 ++++++---- lib/base/scriptutils.cpp | 4 +-- lib/cli/daemoncommand.cpp | 5 ++-- lib/cli/replcommand.cpp | 12 ++++---- lib/config/config_lexer.ll | 10 +++---- lib/config/config_parser.yy | 18 +++++------ lib/config/configitem.cpp | 12 ++++---- lib/config/expression.cpp | 20 ++++++------- lib/config/expression.hpp | 2 +- lib/config/vmops.hpp | 30 +++++++++---------- lib/icinga/dependency-apply.cpp | 16 +++++----- lib/icinga/host.cpp | 2 +- lib/icinga/notification-apply.cpp | 16 +++++----- lib/icinga/scheduleddowntime-apply.cpp | 16 +++++----- lib/icinga/service-apply.cpp | 11 ++++--- test/config-ops.cpp | 10 +++---- 21 files changed, 115 insertions(+), 128 deletions(-) rename lib/base/{configerror.cpp => scripterror.cpp} (81%) rename lib/base/{configerror.hpp => scripterror.hpp} (84%) diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index 57e051a6e..05e2b9324 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -23,11 +23,11 @@ mkclass_target(streamlogger.ti streamlogger.thpp) mkclass_target(sysloglogger.ti sysloglogger.thpp) set(base_SOURCES - application.cpp application-version.cpp application.thpp array.cpp configerror.cpp console.cpp context.cpp + application.cpp application-version.cpp application.thpp array.cpp console.cpp context.cpp convert.cpp debuginfo.cpp dictionary.cpp dynamicobject.cpp dynamicobject.thpp dynamictype.cpp exception.cpp fifo.cpp filelogger.cpp filelogger.thpp initialize.cpp json.cpp logger.cpp logger.thpp netstring.cpp networkstream.cpp object.cpp primitivetype.cpp process.cpp - ringbuffer.cpp scriptfunction.cpp scriptfunctionwrapper.cpp scriptsignal.cpp + ringbuffer.cpp scripterror.cpp scriptfunction.cpp scriptfunctionwrapper.cpp scriptsignal.cpp scriptutils.cpp scriptvariable.cpp serializer.cpp socket.cpp stacktrace.cpp statsfunction.cpp stdiostream.cpp stream.cpp streamlogger.cpp streamlogger.thpp string.cpp sysloglogger.cpp sysloglogger.thpp tcpsocket.cpp thinmutex.cpp threadpool.cpp timer.cpp diff --git a/lib/base/debuginfo.cpp b/lib/base/debuginfo.cpp index 3b4cec312..eeda4f5f8 100644 --- a/lib/base/debuginfo.cpp +++ b/lib/base/debuginfo.cpp @@ -108,11 +108,3 @@ void icinga::ShowCodeFragment(std::ostream& out, const DebugInfo& di, bool verbo } } -std::string icinga::to_string(const errinfo_debuginfo& e) -{ - std::ostringstream msgbuf; - msgbuf << "Config location: " << e.value() << "\n"; - ShowCodeFragment(msgbuf, e.value(), true); - return msgbuf.str(); -} - diff --git a/lib/base/debuginfo.hpp b/lib/base/debuginfo.hpp index 316dc8286..ae55370c3 100644 --- a/lib/base/debuginfo.hpp +++ b/lib/base/debuginfo.hpp @@ -49,11 +49,6 @@ I2_BASE_API DebugInfo DebugInfoRange(const DebugInfo& start, const DebugInfo& en I2_BASE_API void ShowCodeFragment(std::ostream& out, const DebugInfo& di, bool verbose); -struct errinfo_debuginfo_; -typedef boost::error_info errinfo_debuginfo; - -I2_BASE_API std::string to_string(const errinfo_debuginfo& e); - } #endif /* DEBUGINFO_H */ diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index 9d7adabbe..1f9d0868f 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -22,7 +22,7 @@ #include "base/debug.hpp" #include "base/objectlock.hpp" #include "base/convert.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" using namespace icinga; @@ -103,9 +103,9 @@ void DynamicType::RegisterObject(const DynamicObject::Ptr& object) if (it->second == object) return; - 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())); + BOOST_THROW_EXCEPTION(ScriptError("An object with type '" + m_Name + "' and name '" + name + "' already exists (" + + Convert::ToString(it->second->GetDebugInfo()) + "), new declaration: " + Convert::ToString(object->GetDebugInfo()), + object->GetDebugInfo())); } m_ObjectMap[name] = object; diff --git a/lib/base/configerror.cpp b/lib/base/scripterror.cpp similarity index 81% rename from lib/base/configerror.cpp rename to lib/base/scripterror.cpp index 3c43f7fd8..02a3fd1fb 100644 --- a/lib/base/configerror.cpp +++ b/lib/base/scripterror.cpp @@ -17,19 +17,29 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include using namespace icinga; -ConfigError::ConfigError(const String& message) +ScriptError::ScriptError(const String& message) : m_Message(message) { } -ConfigError::~ConfigError(void) throw() +ScriptError::ScriptError(const String& message, const DebugInfo& di) + : m_Message(message), m_DebugInfo(di) { } -const char *ConfigError::what(void) const throw() +ScriptError::~ScriptError(void) throw() +{ } + +const char *ScriptError::what(void) const throw() { return m_Message.CStr(); } + +DebugInfo ScriptError::GetDebugInfo(void) const +{ + return m_DebugInfo; +} + diff --git a/lib/base/configerror.hpp b/lib/base/scripterror.hpp similarity index 84% rename from lib/base/configerror.hpp rename to lib/base/scripterror.hpp index ed6b4f6ef..a92573040 100644 --- a/lib/base/configerror.hpp +++ b/lib/base/scripterror.hpp @@ -17,8 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#ifndef CONFIGERROR_H -#define CONFIGERROR_H +#ifndef SCRIPTERROR_H +#define SCRIPTERROR_H #include "base/i2-base.hpp" #include "base/debuginfo.hpp" @@ -30,18 +30,22 @@ namespace icinga /* * @ingroup base */ -class I2_BASE_API ConfigError : virtual public user_error +class I2_BASE_API ScriptError : virtual public user_error { public: - ConfigError(const String& message); - ~ConfigError(void) throw(); + ScriptError(const String& message); + ScriptError(const String& message, const DebugInfo& di); + ~ScriptError(void) throw(); virtual const char *what(void) const throw(); + DebugInfo GetDebugInfo(void) const; + private: String m_Message; + DebugInfo m_DebugInfo; }; } -#endif /* CONFIGERROR_H */ +#endif /* SCRIPTERROR_H */ diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index 0e11870fd..8f3722d1e 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -26,7 +26,7 @@ #include "base/objectlock.hpp" #include "base/dynamictype.hpp" #include "base/application.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include #include #include @@ -256,6 +256,6 @@ DynamicObject::Ptr ScriptUtils::GetObject(const String& type, const String& name void ScriptUtils::Assert(const Value& arg) { if (!arg.ToBool()) - BOOST_THROW_EXCEPTION(ConfigError("Assertion failed")); + BOOST_THROW_EXCEPTION(std::runtime_error("Assertion failed")); } diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index 85dbfe31b..5f3a42452 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -67,9 +67,8 @@ static void ExecuteExpression(Expression *expression) try { VMFrame frame; expression->Evaluate(frame); - } catch (const ConfigError& ex) { - const DebugInfo *di = boost::get_error_info(ex); - ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } catch (const ScriptError& ex) { + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), ex.GetDebugInfo()); } catch (const std::exception& ex) { ConfigCompilerContext::GetInstance()->AddMessage(true, DiagnosticInformation(ex)); } diff --git a/lib/cli/replcommand.cpp b/lib/cli/replcommand.cpp index 4409dc011..aae29e2bc 100644 --- a/lib/cli/replcommand.cpp +++ b/lib/cli/replcommand.cpp @@ -91,14 +91,12 @@ int ReplCommand::Run(const po::variables_map& vm, const std::vector std::cout << result; std::cout << ConsoleColorTag(Console_Normal) << "\n"; } - } catch (const ConfigError& ex) { - const DebugInfo *di = boost::get_error_info(ex); + } catch (const ScriptError& ex) { + DebugInfo di = ex.GetDebugInfo(); - if (di) { - std::cout << String(3 + di->FirstColumn, ' '); - std::cout << String(di->LastColumn - di->FirstColumn + 1, '^'); - std::cout << "\n"; - } + std::cout << String(3 + di.FirstColumn, ' '); + std::cout << String(di.LastColumn - di.FirstColumn + 1, '^'); + std::cout << "\n"; std::cout << ex.what() << "\n"; } catch (const std::exception& ex) { diff --git a/lib/config/config_lexer.ll b/lib/config/config_lexer.ll index bbb7a6cbd..86a6933aa 100644 --- a/lib/config/config_lexer.ll +++ b/lib/config/config_lexer.ll @@ -84,7 +84,7 @@ do { \ } \n { - BOOST_THROW_EXCEPTION(ConfigError("Unterminated string literal") << errinfo_debuginfo(*yylloc)); + BOOST_THROW_EXCEPTION(ScriptError("Unterminated string literal", *yylloc)); } \\[0-7]{1,3} { @@ -95,7 +95,7 @@ do { \ if (result > 0xff) { /* error, constant is out-of-bounds */ - BOOST_THROW_EXCEPTION(ConfigError("Constant is out of bounds: " + String(yytext)) << errinfo_debuginfo(*yylloc)); + BOOST_THROW_EXCEPTION(ScriptError("Constant is out of bounds: " + String(yytext), *yylloc)); } yyextra->m_LexBuffer << static_cast(result); @@ -105,7 +105,7 @@ do { \ /* generate error - bad escape sequence; something * like '\48' or '\0777777' */ - BOOST_THROW_EXCEPTION(ConfigError("Bad escape sequence found: " + String(yytext)) << errinfo_debuginfo(*yylloc)); + BOOST_THROW_EXCEPTION(ScriptError("Bad escape sequence found: " + String(yytext), *yylloc)); } \\n { yyextra->m_LexBuffer << "\n"; } @@ -122,7 +122,7 @@ do { \ yyextra->m_LexBuffer << *yptr++; } -<> { BOOST_THROW_EXCEPTION(ConfigError("End-of-file while in string literal") << errinfo_debuginfo(*yylloc)); } +<> { BOOST_THROW_EXCEPTION(ScriptError("End-of-file while in string literal", *yylloc)); } \{\{\{ { yyextra->m_LexBuffer.str(""); yyextra->m_LexBuffer.clear(); BEGIN(HEREDOC); } @@ -148,7 +148,7 @@ do { \ } <> { - BOOST_THROW_EXCEPTION(ConfigError("End-of-file while in comment") << errinfo_debuginfo(*yylloc)); + BOOST_THROW_EXCEPTION(ScriptError("End-of-file while in comment", *yylloc)); } diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index bdfad171b..09855dc19 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -34,7 +34,7 @@ #include "base/scriptvariable.hpp" #include "base/exception.hpp" #include "base/dynamictype.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include #include #include @@ -230,7 +230,7 @@ int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner); void yyerror(YYLTYPE *locp, std::vector *, ConfigCompiler *, const char *err) { - BOOST_THROW_EXCEPTION(ConfigError(err) << errinfo_debuginfo(*locp)); + BOOST_THROW_EXCEPTION(ScriptError(err, *locp)); } int yyparse(std::vector *elist, ConfigCompiler *context); @@ -465,7 +465,7 @@ object: if (seen_assign) { if (!ObjectRule::IsValidSourceType(type)) - BOOST_THROW_EXCEPTION(ConfigError("object rule 'assign' cannot be used for type '" + type + "'") << errinfo_debuginfo(DebugInfoRange(@2, @3))); + BOOST_THROW_EXCEPTION(ScriptError("object rule 'assign' cannot be used for type '" + type + "'", DebugInfoRange(@2, @3))); if (ignore) { Expression *rex = new LogicalNegateExpression(ignore, DebugInfoRange(@2, @5)); @@ -625,7 +625,7 @@ lterm: type | T_ASSIGN T_WHERE rterm { if ((context->m_Apply.empty() || !context->m_Apply.top()) && (context->m_ObjectAssign.empty() || !context->m_ObjectAssign.top())) - BOOST_THROW_EXCEPTION(ConfigError("'assign' keyword not valid in this context.")); + BOOST_THROW_EXCEPTION(ScriptError("'assign' keyword not valid in this context.", DebugInfoRange(@1, @3))); context->m_SeenAssign.top() = true; @@ -639,7 +639,7 @@ lterm: type | T_IGNORE T_WHERE rterm { if ((context->m_Apply.empty() || !context->m_Apply.top()) && (context->m_ObjectAssign.empty() || !context->m_ObjectAssign.top())) - BOOST_THROW_EXCEPTION(ConfigError("'ignore' keyword not valid in this context.")); + BOOST_THROW_EXCEPTION(ScriptError("'ignore' keyword not valid in this context.", DebugInfoRange(@1, @3))); if (context->m_Ignore.top()) context->m_Ignore.top() = new LogicalOrExpression(context->m_Ignore.top(), $3, DebugInfoRange(@1, @3)); @@ -962,7 +962,7 @@ apply: free($6); if (!ApplyRule::IsValidSourceType(type)) - BOOST_THROW_EXCEPTION(ConfigError("'apply' cannot be used with type '" + type + "'") << errinfo_debuginfo(DebugInfoRange(@2, @3))); + BOOST_THROW_EXCEPTION(ScriptError("'apply' cannot be used with type '" + type + "'", DebugInfoRange(@2, @3))); if (!ApplyRule::IsValidTargetType(type, target)) { if (target == "") { @@ -980,9 +980,9 @@ apply: typeNames += "'" + types[i] + "'"; } - BOOST_THROW_EXCEPTION(ConfigError("'apply' target type is ambiguous (can be one of " + typeNames + "): use 'to' to specify a type") << errinfo_debuginfo(DebugInfoRange(@2, @3))); + BOOST_THROW_EXCEPTION(ScriptError("'apply' target type is ambiguous (can be one of " + typeNames + "): use 'to' to specify a type", DebugInfoRange(@2, @3))); } else - BOOST_THROW_EXCEPTION(ConfigError("'apply' target type '" + target + "' is invalid") << errinfo_debuginfo(DebugInfoRange(@2, @5))); + BOOST_THROW_EXCEPTION(ScriptError("'apply' target type '" + target + "' is invalid", DebugInfoRange(@2, @5))); } DictExpression *exprl = dynamic_cast($8); @@ -990,7 +990,7 @@ apply: // assign && !ignore if (!context->m_SeenAssign.top()) - BOOST_THROW_EXCEPTION(ConfigError("'apply' is missing 'assign'") << errinfo_debuginfo(DebugInfoRange(@2, @3))); + BOOST_THROW_EXCEPTION(ScriptError("'apply' is missing 'assign'", DebugInfoRange(@2, @3))); context->m_SeenAssign.pop(); diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 7b4c43d56..4d07a216e 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -34,7 +34,7 @@ #include "base/netstring.hpp" #include "base/serializer.hpp" #include "base/json.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include #include #include @@ -167,9 +167,8 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard) VMFrame frame(dobj); frame.Locals = m_Scope; m_Expression->Evaluate(frame, &debugHints); - } catch (const ConfigError& ex) { - const DebugInfo *di = boost::get_error_info(ex); - ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } catch (const ScriptError& ex) { + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), ex.GetDebugInfo()); } catch (const std::exception& ex) { ConfigCompilerContext::GetInstance()->AddMessage(true, DiagnosticInformation(ex)); } @@ -229,9 +228,8 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard) try { ctype->ValidateItem(GetName(), dobj, GetDebugInfo(), &utils); - } catch (const ConfigError& ex) { - const DebugInfo *di = boost::get_error_info(ex); - ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } catch (const ScriptError& ex) { + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), ex.GetDebugInfo()); } catch (const std::exception& ex) { ConfigCompilerContext::GetInstance()->AddMessage(true, DiagnosticInformation(ex)); } diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp index 8fcdcd177..27ced4aa2 100644 --- a/lib/config/expression.cpp +++ b/lib/config/expression.cpp @@ -24,7 +24,7 @@ #include "base/json.hpp" #include "base/object.hpp" #include "base/logger.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include #include #include @@ -47,13 +47,11 @@ Value Expression::Evaluate(VMFrame& frame, DebugHint *dhint) const return DoEvaluate(frame, dhint); } catch (const InterruptExecutionError&) { throw; + } catch (const ScriptError& ex) { + throw; } catch (const std::exception& ex) { - if (boost::get_error_info(ex)) - throw; - else - BOOST_THROW_EXCEPTION(ConfigError("Error while evaluating expression: " + String(ex.what())) - << boost::errinfo_nested_exception(boost::current_exception()) - << errinfo_debuginfo(GetDebugInfo())); + BOOST_THROW_EXCEPTION(ScriptError("Error while evaluating expression: " + String(ex.what()), GetDebugInfo()) + << boost::errinfo_nested_exception(boost::current_exception())); } } @@ -191,7 +189,7 @@ Value InExpression::DoEvaluate(VMFrame& frame, DebugHint *dhint) const if (right.IsEmpty()) return false; else if (!right.IsObjectType()) - BOOST_THROW_EXCEPTION(ConfigError("Invalid right side argument for 'in' operator: " + JsonEncode(right))); + BOOST_THROW_EXCEPTION(ScriptError("Invalid right side argument for 'in' operator: " + JsonEncode(right), GetDebugInfo())); Value left = m_Operand1->Evaluate(frame); @@ -206,7 +204,7 @@ Value NotInExpression::DoEvaluate(VMFrame& frame, DebugHint *dhint) const if (right.IsEmpty()) return true; else if (!right.IsObjectType()) - BOOST_THROW_EXCEPTION(ConfigError("Invalid right side argument for 'in' operator: " + JsonEncode(right))); + BOOST_THROW_EXCEPTION(ScriptError("Invalid right side argument for 'in' operator: " + JsonEncode(right), GetDebugInfo())); Value left = m_Operand1->Evaluate(frame); @@ -292,7 +290,7 @@ Value SetExpression::DoEvaluate(VMFrame& frame, DebugHint *dhint) const object = indexExpr->Evaluate(frame, dhint); if (!object) - BOOST_THROW_EXCEPTION(ConfigError("Left-hand side argument must not be null.")); + BOOST_THROW_EXCEPTION(ScriptError("Left-hand side argument must not be null.", GetDebugInfo())); continue; } @@ -400,7 +398,7 @@ Value ImportExpression::DoEvaluate(VMFrame& frame, DebugHint *dhint) const ConfigItem::Ptr item = ConfigItem::GetObject(type, name); if (!item) - BOOST_THROW_EXCEPTION(ConfigError("Import references unknown template: '" + name + "'")); + BOOST_THROW_EXCEPTION(ScriptError("Import references unknown template: '" + name + "'", GetDebugInfo())); item->GetExpression()->Evaluate(frame, dhint); diff --git a/lib/config/expression.hpp b/lib/config/expression.hpp index 17ad784ad..924c44783 100644 --- a/lib/config/expression.hpp +++ b/lib/config/expression.hpp @@ -26,7 +26,7 @@ #include "base/array.hpp" #include "base/dictionary.hpp" #include "base/scriptfunction.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include "base/convert.hpp" #include #include diff --git a/lib/config/vmops.hpp b/lib/config/vmops.hpp index f2d2f5d44..dbef565f8 100644 --- a/lib/config/vmops.hpp +++ b/lib/config/vmops.hpp @@ -31,7 +31,7 @@ #include "base/scriptfunction.hpp" #include "base/scriptsignal.hpp" #include "base/scriptvariable.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include "base/convert.hpp" #include "base/objectlock.hpp" #include @@ -67,7 +67,7 @@ public: func = ScriptFunction::GetByName(funcName); if (!func) - BOOST_THROW_EXCEPTION(ConfigError("Function '" + funcName + "' does not exist.")); + BOOST_THROW_EXCEPTION(ScriptError("Function '" + funcName + "' does not exist.")); return func->Invoke(arguments); } @@ -104,7 +104,7 @@ public: ScriptSignal::Ptr sig = ScriptSignal::GetByName(signal); if (!sig) - BOOST_THROW_EXCEPTION(ConfigError("Signal '" + signal + "' does not exist.")); + BOOST_THROW_EXCEPTION(ScriptError("Signal '" + signal + "' does not exist.")); sig->AddSlot(boost::bind(SlotWrapper, slot, _1)); @@ -143,7 +143,7 @@ public: if (oldItem) { std::ostringstream msgbuf; msgbuf << "Object '" << name << "' of type '" << type << "' re-defined: " << debugInfo << "; previous definition: " << oldItem->GetDebugInfo(); - BOOST_THROW_EXCEPTION(ConfigError(msgbuf.str()) << errinfo_debuginfo(debugInfo)); + BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debugInfo)); } } @@ -152,7 +152,7 @@ public: if (name.FindFirstOf("!") != String::NPos) { std::ostringstream msgbuf; msgbuf << "Name for object '" << name << "' of type '" << type << "' is invalid: Object names may not contain '!'"; - BOOST_THROW_EXCEPTION(ConfigError(msgbuf.str()) << errinfo_debuginfo(debugInfo)); + BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debugInfo)); } item->SetName(name); @@ -171,7 +171,7 @@ public: { if (value.IsObjectType()) { if (!fvvar.IsEmpty()) - BOOST_THROW_EXCEPTION(ConfigError("Cannot use dictionary iterator for array.") << errinfo_debuginfo(debugInfo)); + BOOST_THROW_EXCEPTION(ScriptError("Cannot use dictionary iterator for array.", debugInfo)); Array::Ptr arr = value; @@ -182,7 +182,7 @@ public: } } else if (value.IsObjectType()) { if (fvvar.IsEmpty()) - BOOST_THROW_EXCEPTION(ConfigError("Cannot use array iterator for dictionary.") << errinfo_debuginfo(debugInfo)); + BOOST_THROW_EXCEPTION(ScriptError("Cannot use array iterator for dictionary.", debugInfo)); Dictionary::Ptr dict = value; @@ -194,7 +194,7 @@ public: } } else - BOOST_THROW_EXCEPTION(ConfigError("Invalid type in __for expression: " + value.GetTypeName()) << errinfo_debuginfo(debugInfo)); + BOOST_THROW_EXCEPTION(ScriptError("Invalid type in __for expression: " + value.GetTypeName(), debugInfo)); return Empty; } @@ -242,7 +242,7 @@ public: return context->GetField(fid); } - static inline void SetField(const Object::Ptr& context, const String& field, const Value& value) + static inline void SetField(const Object::Ptr& context, const String& field, const Value& value, const DebugInfo& debugInfo = DebugInfo()) { Dictionary::Ptr dict = dynamic_pointer_cast(context); @@ -264,19 +264,19 @@ public: Type::Ptr type = context->GetReflectionType(); if (!type) - BOOST_THROW_EXCEPTION(ConfigError("Cannot set field on object.")); + BOOST_THROW_EXCEPTION(ScriptError("Cannot set field on object.", debugInfo)); int fid = type->GetFieldId(field); if (fid == -1) - BOOST_THROW_EXCEPTION(ConfigError("Attribute '" + field + "' does not exist.")); + BOOST_THROW_EXCEPTION(ScriptError("Attribute '" + field + "' does not exist.", debugInfo)); try { context->SetField(fid, value); } catch (const boost::bad_lexical_cast&) { - BOOST_THROW_EXCEPTION(ConfigError("Attribute '" + field + "' cannot be set to value of type '" + value.GetTypeName() + "'")); + BOOST_THROW_EXCEPTION(ScriptError("Attribute '" + field + "' cannot be set to value of type '" + value.GetTypeName() + "'", debugInfo)); } catch (const std::bad_cast&) { - BOOST_THROW_EXCEPTION(ConfigError("Attribute '" + field + "' cannot be set to value of type '" + value.GetTypeName() + "'")); + BOOST_THROW_EXCEPTION(ScriptError("Attribute '" + field + "' cannot be set to value of type '" + value.GetTypeName() + "'", debugInfo)); } } @@ -285,7 +285,7 @@ private: const std::vector& funcargs, const Dictionary::Ptr& closedVars, const boost::shared_ptr& expr) { if (arguments.size() < funcargs.size()) - BOOST_THROW_EXCEPTION(ConfigError("Too few arguments for function")); + BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function")); VMFrame frame; @@ -315,7 +315,7 @@ private: func = ScriptFunction::GetByName(funcName); if (!func) - BOOST_THROW_EXCEPTION(ConfigError("Function '" + funcName + "' does not exist.")); + BOOST_THROW_EXCEPTION(ScriptError("Function '" + funcName + "' does not exist.")); func->Invoke(arguments); } diff --git a/lib/icinga/dependency-apply.cpp b/lib/icinga/dependency-apply.cpp index 788c859b3..10227d9cf 100644 --- a/lib/icinga/dependency-apply.cpp +++ b/lib/icinga/dependency-apply.cpp @@ -27,7 +27,7 @@ #include "base/logger.hpp" #include "base/context.hpp" #include "base/workqueue.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include using namespace icinga; @@ -109,7 +109,7 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR if (vinstances.IsObjectType()) { if (!rule.GetFVVar().IsEmpty()) - BOOST_THROW_EXCEPTION(ConfigError("Array iterator requires value to be an array.") << errinfo_debuginfo(di)); + BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di)); Array::Ptr arr = vinstances; @@ -126,7 +126,7 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR } } else if (vinstances.IsObjectType()) { if (rule.GetFVVar().IsEmpty()) - BOOST_THROW_EXCEPTION(ConfigError("Dictionary iterator requires value to be a dictionary.") << errinfo_debuginfo(di)); + BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di)); Dictionary::Ptr dict = vinstances; @@ -153,9 +153,8 @@ void Dependency::EvaluateApplyRules(const Host::Ptr& host) try { if (EvaluateApplyRule(host, rule)) rule.AddMatch(); - } catch (const ConfigError& ex) { - const DebugInfo *di = boost::get_error_info(ex); - ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } catch (const ScriptError& ex) { + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), ex.GetDebugInfo()); } } } @@ -171,9 +170,8 @@ void Dependency::EvaluateApplyRules(const Service::Ptr& service) try { if (EvaluateApplyRule(service, rule)) rule.AddMatch(); - } catch (const ConfigError& ex) { - const DebugInfo *di = boost::get_error_info(ex); - ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } catch (const ScriptError& ex) { + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), ex.GetDebugInfo()); } } } diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 1a7fe818d..c87d1674d 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -23,7 +23,7 @@ #include "icinga/pluginutility.hpp" #include "icinga/scheduleddowntime.hpp" #include "config/configcompilercontext.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include "base/objectlock.hpp" #include "base/convert.hpp" #include "base/utility.hpp" diff --git a/lib/icinga/notification-apply.cpp b/lib/icinga/notification-apply.cpp index f7e226935..c8ef7d788 100644 --- a/lib/icinga/notification-apply.cpp +++ b/lib/icinga/notification-apply.cpp @@ -27,7 +27,7 @@ #include "base/logger.hpp" #include "base/context.hpp" #include "base/workqueue.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include using namespace icinga; @@ -108,7 +108,7 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl if (vinstances.IsObjectType()) { if (!rule.GetFVVar().IsEmpty()) - BOOST_THROW_EXCEPTION(ConfigError("Array iterator requires value to be an array.") << errinfo_debuginfo(di)); + BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di)); Array::Ptr arr = vinstances; @@ -125,7 +125,7 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl } } else if (vinstances.IsObjectType()) { if (rule.GetFVVar().IsEmpty()) - BOOST_THROW_EXCEPTION(ConfigError("Dictionary iterator requires value to be a dictionary.") << errinfo_debuginfo(di)); + BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di)); Dictionary::Ptr dict = vinstances; @@ -153,9 +153,8 @@ void Notification::EvaluateApplyRules(const Host::Ptr& host) try { if (EvaluateApplyRule(host, rule)) rule.AddMatch(); - } catch (const ConfigError& ex) { - const DebugInfo *di = boost::get_error_info(ex); - ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } catch (const ScriptError& ex) { + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), ex.GetDebugInfo()); } } } @@ -171,9 +170,8 @@ void Notification::EvaluateApplyRules(const Service::Ptr& service) try { if (EvaluateApplyRule(service, rule)) rule.AddMatch(); - } catch (const ConfigError& ex) { - const DebugInfo *di = boost::get_error_info(ex); - ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } catch (const ScriptError& ex) { + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), ex.GetDebugInfo()); } } } diff --git a/lib/icinga/scheduleddowntime-apply.cpp b/lib/icinga/scheduleddowntime-apply.cpp index 78223dbbb..f2c7ca304 100644 --- a/lib/icinga/scheduleddowntime-apply.cpp +++ b/lib/icinga/scheduleddowntime-apply.cpp @@ -26,7 +26,7 @@ #include "base/dynamictype.hpp" #include "base/logger.hpp" #include "base/context.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include using namespace icinga; @@ -107,7 +107,7 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const if (vinstances.IsObjectType()) { if (!rule.GetFVVar().IsEmpty()) - BOOST_THROW_EXCEPTION(ConfigError("Array iterator requires value to be an array.") << errinfo_debuginfo(di)); + BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di)); Array::Ptr arr = vinstances; @@ -124,7 +124,7 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const } } else if (vinstances.IsObjectType()) { if (rule.GetFVVar().IsEmpty()) - BOOST_THROW_EXCEPTION(ConfigError("Dictionary iterator requires value to be a dictionary.") << errinfo_debuginfo(di)); + BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di)); Dictionary::Ptr dict = vinstances; @@ -151,9 +151,8 @@ void ScheduledDowntime::EvaluateApplyRules(const Host::Ptr& host) try { if (EvaluateApplyRule(host, rule)) rule.AddMatch(); - } catch (const ConfigError& ex) { - const DebugInfo *di = boost::get_error_info(ex); - ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } catch (const ScriptError& ex) { + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), ex.GetDebugInfo()); } } } @@ -169,9 +168,8 @@ void ScheduledDowntime::EvaluateApplyRules(const Service::Ptr& service) try { if (EvaluateApplyRule(service, rule)) rule.AddMatch(); - } catch (const ConfigError& ex) { - const DebugInfo *di = boost::get_error_info(ex); - ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } catch (const ScriptError& ex) { + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), ex.GetDebugInfo()); } } } diff --git a/lib/icinga/service-apply.cpp b/lib/icinga/service-apply.cpp index 591e58a65..74c9d5143 100644 --- a/lib/icinga/service-apply.cpp +++ b/lib/icinga/service-apply.cpp @@ -26,7 +26,7 @@ #include "base/logger.hpp" #include "base/context.hpp" #include "base/workqueue.hpp" -#include "base/configerror.hpp" +#include "base/scripterror.hpp" #include using namespace icinga; @@ -95,7 +95,7 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule) if (vinstances.IsObjectType()) { if (!rule.GetFVVar().IsEmpty()) - BOOST_THROW_EXCEPTION(ConfigError("Array iterator requires value to be an array.") << errinfo_debuginfo(di)); + BOOST_THROW_EXCEPTION(ScriptError("Array iterator requires value to be an array.", di)); Array::Ptr arr = vinstances; @@ -112,7 +112,7 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule) } } else if (vinstances.IsObjectType()) { if (rule.GetFVVar().IsEmpty()) - BOOST_THROW_EXCEPTION(ConfigError("Dictionary iterator requires value to be a dictionary.") << errinfo_debuginfo(di)); + BOOST_THROW_EXCEPTION(ScriptError("Dictionary iterator requires value to be a dictionary.", di)); Dictionary::Ptr dict = vinstances; @@ -136,9 +136,8 @@ void Service::EvaluateApplyRules(const Host::Ptr& host) try { if (EvaluateApplyRule(host, rule)) rule.AddMatch(); - } catch (const ConfigError& ex) { - const DebugInfo *di = boost::get_error_info(ex); - ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo()); + } catch (const ScriptError& ex) { + ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), ex.GetDebugInfo()); } } } diff --git a/test/config-ops.cpp b/test/config-ops.cpp index aa7f09062..e7d88e2c8 100644 --- a/test/config-ops.cpp +++ b/test/config-ops.cpp @@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(simple) delete expr; expr = ConfigCompiler::CompileText("", "\"foo\" in \"bar\""); - BOOST_CHECK_THROW(expr->Evaluate(frame), ConfigError); + BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError); delete expr; expr = ConfigCompiler::CompileText("", "\"foo\" !in [ \"bar\", \"baz\" ]"); @@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(simple) delete expr; expr = ConfigCompiler::CompileText("", "\"foo\" !in \"bar\""); - BOOST_CHECK_THROW(expr->Evaluate(frame), ConfigError); + BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError); delete expr; expr = ConfigCompiler::CompileText("", "{ a += 3 }"); @@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(simple) BOOST_CHECK(dict->Get("a") == 3); expr = ConfigCompiler::CompileText("", "test"); - BOOST_CHECK_THROW(expr->Evaluate(frame), ConfigError); + BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError); delete expr; expr = ConfigCompiler::CompileText("", "null + 3"); @@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(advanced) delete expr; expr = ConfigCompiler::CompileText("", "__boost_test()"); - BOOST_CHECK_THROW(expr->Evaluate(frame), ConfigError); + BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError); delete expr; Object::Ptr self = new Object(); @@ -237,7 +237,7 @@ BOOST_AUTO_TEST_CASE(advanced) delete expr; expr = ConfigCompiler::CompileText("", "a = 3 b = 3"); - BOOST_CHECK_THROW(expr->Evaluate(frame), ConfigError); + BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError); expr = ConfigCompiler::CompileText("", "__function() { 3 }()"); BOOST_CHECK(expr->Evaluate(frame) == 3);