[icinga-checkins] icinga.org: icinga2/master: Print DebugInfo for failed #includes

git at icinga.org git at icinga.org
Sun Feb 3 01:41:18 CET 2013


Module: icinga2
Branch: master
Commit: a88d9b56464d86351a890b5b07dc49346e646633
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=a88d9b56464d86351a890b5b07dc49346e646633

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sun Feb  3 01:41:00 2013 +0100

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 1a473b1..8dbf738 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 9330e0a..5c9a3a7 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 a4332b4..fd9c072 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<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) {
 		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<ConfigItem::Ptr> *resultItems, vector<ConfigType::Ptr> *resultTypes)
+    vector<ConfigItem::Ptr> *resultItems, vector<ConfigType::Ptr> *resultTypes, const DebugInfo& debuginfo)
 {
 	String includePath = include;
 
@@ -229,8 +234,11 @@ void ConfigCompiler::HandleFileInclude(const String& include, bool search,
 
 	vector<ConfigItem::Ptr> 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 c697162..006e544 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<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,
 	    HandleIncludeFunc includeHandler = &ConfigCompiler::HandleFileInclude);
@@ -54,10 +55,11 @@ public:
 	String GetPath(void) const;
 
 	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 */
-	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);





More information about the icinga-checkins mailing list