From a88d9b56464d86351a890b5b07dc49346e646633 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 3 Feb 2013 01:41:00 +0100 Subject: [PATCH] Print DebugInfo for failed #includes Fixes #3613 --- lib/config/config_parser.cc | 4 ++-- lib/config/config_parser.yy | 4 ++-- lib/config/configcompiler.cpp | 18 +++++++++++++----- lib/config/configcompiler.h | 8 +++++--- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/config/config_parser.cc b/lib/config/config_parser.cc index 1a473b1f2..8dbf738bf 100644 --- a/lib/config/config_parser.cc +++ b/lib/config/config_parser.cc @@ -1618,7 +1618,7 @@ yyreduce: /* Line 1806 of yacc.c */ #line 118 "config_parser.yy" { - context->HandleInclude((yyvsp[(2) - (2)].text), false); + context->HandleInclude((yyvsp[(2) - (2)].text), false, yylloc); } break; @@ -1627,7 +1627,7 @@ yyreduce: /* Line 1806 of yacc.c */ #line 122 "config_parser.yy" { - context->HandleInclude((yyvsp[(2) - (2)].text), true); + context->HandleInclude((yyvsp[(2) - (2)].text), true, yylloc); } break; diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index 9330e0a75..5c9a3a7f3 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -116,11 +116,11 @@ statement: object | type | include | library include: T_INCLUDE T_STRING { - context->HandleInclude($2, false); + context->HandleInclude($2, false, yylloc); } | T_INCLUDE T_STRING_ANGLE { - context->HandleInclude($2, true); + context->HandleInclude($2, true, yylloc); } library: T_LIBRARY T_STRING diff --git a/lib/config/configcompiler.cpp b/lib/config/configcompiler.cpp index a4332b493..fd9c07298 100644 --- a/lib/config/configcompiler.cpp +++ b/lib/config/configcompiler.cpp @@ -114,13 +114,14 @@ String ConfigCompiler::GetPath(void) const * * @param include The path from the include directive. * @param search Whether to search global include dirs. + * @param debuginfo Debug information. */ -void ConfigCompiler::HandleInclude(const String& include, bool search) +void ConfigCompiler::HandleInclude(const String& include, bool search, const DebugInfo& debuginfo) { String path = Utility::DirName(GetPath()) + "/" + include; vector types; - m_HandleInclude(path, search, &m_ResultObjects, &types); + m_HandleInclude(path, search, &m_ResultObjects, &types, debuginfo); BOOST_FOREACH(const ConfigType::Ptr& type, types) { AddType(type); @@ -202,9 +203,13 @@ void ConfigCompiler::CompileText(const String& path, const String& text, * configuration items. * * @param include The path from the include directive. + * @param search Whether to search include dirs. + * @param resultItems The resulting items. + * @param resultTypes The resulting types. + * @param debuginfo Debug information. */ void ConfigCompiler::HandleFileInclude(const String& include, bool search, - vector *resultItems, vector *resultTypes) + vector *resultItems, vector *resultTypes, const DebugInfo& debuginfo) { String includePath = include; @@ -229,8 +234,11 @@ void ConfigCompiler::HandleFileInclude(const String& include, bool search, vector items; - if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CompileFile, _1, resultItems, resultTypes))) - throw_exception(invalid_argument("Include file '" + include + "' does not exist (or no files found for pattern).")); + if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CompileFile, _1, resultItems, resultTypes))) { + stringstream msgbuf; + msgbuf << "Include file '" + include + "' does not exist (or no files found for pattern): " << debuginfo; + throw_exception(invalid_argument(msgbuf.str())); + } } /** diff --git a/lib/config/configcompiler.h b/lib/config/configcompiler.h index c697162c6..006e54432 100644 --- a/lib/config/configcompiler.h +++ b/lib/config/configcompiler.h @@ -32,7 +32,8 @@ namespace icinga class I2_CONFIG_API ConfigCompiler { public: - typedef function *, vector *)> HandleIncludeFunc; + typedef function *, + vector *, const DebugInfo&)> HandleIncludeFunc; ConfigCompiler(const String& path, istream *input = &cin, HandleIncludeFunc includeHandler = &ConfigCompiler::HandleFileInclude); @@ -54,10 +55,11 @@ public: String GetPath(void) const; static void HandleFileInclude(const String& include, bool search, - vector *resultItems, vector *resultTypes); + vector *resultItems, vector *resultTypes, + const DebugInfo& debuginfo); /* internally used methods */ - void HandleInclude(const String& include, bool search); + void HandleInclude(const String& include, bool search, const DebugInfo& debuginfo); void HandleLibrary(const String& library); void AddObject(const ConfigItem::Ptr& object);