Print DebugInfo for failed #includes

Fixes #3613
This commit is contained in:
Gunnar Beutner 2013-02-03 01:41:00 +01:00
parent 383d2369b1
commit a88d9b5646
4 changed files with 22 additions and 12 deletions

View File

@ -1618,7 +1618,7 @@ yyreduce:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 118 "config_parser.yy" #line 118 "config_parser.yy"
{ {
context->HandleInclude((yyvsp[(2) - (2)].text), false); context->HandleInclude((yyvsp[(2) - (2)].text), false, yylloc);
} }
break; break;
@ -1627,7 +1627,7 @@ yyreduce:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 122 "config_parser.yy" #line 122 "config_parser.yy"
{ {
context->HandleInclude((yyvsp[(2) - (2)].text), true); context->HandleInclude((yyvsp[(2) - (2)].text), true, yylloc);
} }
break; break;

View File

@ -116,11 +116,11 @@ statement: object | type | include | library
include: T_INCLUDE T_STRING include: T_INCLUDE T_STRING
{ {
context->HandleInclude($2, false); context->HandleInclude($2, false, yylloc);
} }
| T_INCLUDE T_STRING_ANGLE | T_INCLUDE T_STRING_ANGLE
{ {
context->HandleInclude($2, true); context->HandleInclude($2, true, yylloc);
} }
library: T_LIBRARY T_STRING library: T_LIBRARY T_STRING

View File

@ -114,13 +114,14 @@ String ConfigCompiler::GetPath(void) const
* *
* @param include The path from the include directive. * @param include The path from the include directive.
* @param search Whether to search global include dirs. * @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; String path = Utility::DirName(GetPath()) + "/" + include;
vector<ConfigType::Ptr> types; vector<ConfigType::Ptr> types;
m_HandleInclude(path, search, &m_ResultObjects, &types); m_HandleInclude(path, search, &m_ResultObjects, &types, debuginfo);
BOOST_FOREACH(const ConfigType::Ptr& type, types) { BOOST_FOREACH(const ConfigType::Ptr& type, types) {
AddType(type); AddType(type);
@ -202,9 +203,13 @@ void ConfigCompiler::CompileText(const String& path, const String& text,
* configuration items. * configuration items.
* *
* @param include The path from the include directive. * @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, void ConfigCompiler::HandleFileInclude(const String& include, bool search,
vector<ConfigItem::Ptr> *resultItems, vector<ConfigType::Ptr> *resultTypes) vector<ConfigItem::Ptr> *resultItems, vector<ConfigType::Ptr> *resultTypes, const DebugInfo& debuginfo)
{ {
String includePath = include; String includePath = include;
@ -229,8 +234,11 @@ void ConfigCompiler::HandleFileInclude(const String& include, bool search,
vector<ConfigItem::Ptr> items; vector<ConfigItem::Ptr> items;
if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CompileFile, _1, resultItems, resultTypes))) 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).")); stringstream msgbuf;
msgbuf << "Include file '" + include + "' does not exist (or no files found for pattern): " << debuginfo;
throw_exception(invalid_argument(msgbuf.str()));
}
} }
/** /**

View File

@ -32,7 +32,8 @@ namespace icinga
class I2_CONFIG_API ConfigCompiler class I2_CONFIG_API ConfigCompiler
{ {
public: public:
typedef function<void (const String&, bool, vector<ConfigItem::Ptr> *, vector<ConfigType::Ptr> *)> HandleIncludeFunc; typedef function<void (const String&, bool, vector<ConfigItem::Ptr> *,
vector<ConfigType::Ptr> *, const DebugInfo&)> HandleIncludeFunc;
ConfigCompiler(const String& path, istream *input = &cin, ConfigCompiler(const String& path, istream *input = &cin,
HandleIncludeFunc includeHandler = &ConfigCompiler::HandleFileInclude); HandleIncludeFunc includeHandler = &ConfigCompiler::HandleFileInclude);
@ -54,10 +55,11 @@ public:
String GetPath(void) const; String GetPath(void) const;
static void HandleFileInclude(const String& include, bool search, static void HandleFileInclude(const String& include, bool search,
vector<ConfigItem::Ptr> *resultItems, vector<ConfigType::Ptr> *resultTypes); vector<ConfigItem::Ptr> *resultItems, vector<ConfigType::Ptr> *resultTypes,
const DebugInfo& debuginfo);
/* internally used methods */ /* 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 HandleLibrary(const String& library);
void AddObject(const ConfigItem::Ptr& object); void AddObject(const ConfigItem::Ptr& object);