From d2fb8a91817b8f2b9e27b2a85370e694e92a3915 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Wed, 1 Feb 2023 09:30:49 +0100 Subject: [PATCH] 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. --- icinga-app/icinga.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index be8a10ae4..f3e04dc76 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -427,8 +427,13 @@ static int Main() std::unique_ptr 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; + } } }