From b4472b74a0837f7b352ec8c5267ebfca41bd1e60 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Tue, 13 Jan 2026 17:17:21 +0100 Subject: [PATCH] MT#63980 fix Javascript prov templates raising errors The JE module will populate $@, hence an enclosing eval{} wipes the error string unintentionally. in addition the "die" method is now exposed in Javascript templates, to use it to bail out, ie. to propagate a msg from an input validation to the UI. Change-Id: Id3fcf8a7820ee3df51e0cc6323350f5f5908fcf4 (cherry picked from commit 5fb5a860c3bdb12fa0e5c1ed55f61489115aeda7) --- lib/NGCP/Panel/Utils/ProvisioningTemplates.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm b/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm index b5b73d0aeb..35557ed821 100644 --- a/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm +++ b/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm @@ -465,6 +465,14 @@ sub provision_begin { _unbox_je_value($_); } @_); }; + $subs{'trim'} = sub { + my $string = _unbox_je_value(shift @_); + $string =~ s/^\s+|\s+$//g; + return $string; + }; + $subs{'die'} = sub { + return die(( map { _unbox_je_value($_); } @_)); + }; while (each %subs) { $context->{_je}->new_function($_ => $subs{$_}); } @@ -1433,11 +1441,13 @@ sub _calculate { ";\n_func = $c;"); die("$f: " . $@) if $@; my $v; + my $err; eval { $v = _unbox_je_value($context->{_je}->eval('_func();')); + $err = $@; }; - if ($@) { - die("$f: " . $@); + if ($err or ($err = $@)) { + die("$f: " . $err); } return ($1 => $v);