Handle errors when evaluating --define

This can be observed when running something like `icinga2 daemon -C -DTypes.Host=42`.

Without this commit:

    [2023-02-01 09:29:00 +0100] critical/Application: Error: Namespace is read-only and must not be modified.

    Additional information is available in '/var/log/icinga2/crash/report.1675240140.425155'

With this commit:

    [2023-02-01 09:30:37 +0100] critical/icinga-app: cannot set 'Types.Host': Namespace is read-only and must not be modified.
This commit is contained in:
Julian Brost 2023-02-01 09:30:49 +01:00
parent a24375bc91
commit d2fb8a9181
1 changed files with 7 additions and 2 deletions

View File

@ -427,8 +427,13 @@ static int Main()
std::unique_ptr<SetExpression> setExpr{new SetExpression(std::move(expr), OpSetLiteral, MakeLiteral(value))};
setExpr->SetOverrideFrozen();
ScriptFrame frame(true);
setExpr->Evaluate(frame);
try {
ScriptFrame frame(true);
setExpr->Evaluate(frame);
} catch (const ScriptError& e) {
Log(LogCritical, "icinga-app") << "cannot set '" << key << "': " << e.what();
return EXIT_FAILURE;
}
}
}