return typeSpec.SubStr(index + 1);
}
+static void ExecuteExpression(Expression *expression)
+{
+ Dictionary::Ptr context = new Dictionary();
+
+ try {
+ expression->Evaluate(context);
+ } catch (const ConfigError& ex) {
+ const DebugInfo *di = boost::get_error_info<errinfo_debuginfo>(ex);
+ ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo());
+ } catch (const std::exception& ex) {
+ ConfigCompilerContext::GetInstance()->AddMessage(true, DiagnosticInformation(ex));
+ }
+}
+
static void IncludeZoneDirRecursive(const String& path)
{
String zoneName = Utility::BaseName(path);
std::vector<Expression *> expressions;
Utility::GlobRecursive(path, "*.conf", boost::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName), GlobFile);
- Dictionary::Ptr context = new Dictionary();
- DictExpression(expressions).Evaluate(context);
+ DictExpression expr(expressions);
+ ExecuteExpression(&expr);
}
static void IncludeNonLocalZone(const String& zonePath)
if (vm.count("config") > 0) {
BOOST_FOREACH(const String& configPath, vm["config"].as<std::vector<std::string> >()) {
Expression *expression = ConfigCompiler::CompileFile(configPath);
- Dictionary::Ptr context = new Dictionary();
- expression->Evaluate(context);
+ ExecuteExpression(expression);
+ delete expression;
}
} else if (!vm.count("no-config")) {
Expression *expression = ConfigCompiler::CompileFile(Application::GetSysconfDir() + "/icinga2/icinga2.conf");
- Dictionary::Ptr context = new Dictionary();
- expression->Evaluate(context);
+ ExecuteExpression(expression);
+ delete expression;
}
/* Load cluster config files - this should probably be in libremote but
String name, fragment;
BOOST_FOREACH(boost::tie(name, fragment), ConfigFragmentRegistry::GetInstance()->GetItems()) {
Expression *expression = ConfigCompiler::CompileText(name, fragment);
- Dictionary::Ptr context = new Dictionary();
- expression->Evaluate(context);
+ ExecuteExpression(expression);
+ delete expression;
}
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder();