Merge branch 'func-exit-error' into next

This commit is contained in:
Christian Hesse 2024-12-09 09:13:18 +01:00
commit 519cb85e28
12 changed files with 77 additions and 39 deletions

View file

@ -428,13 +428,15 @@
# simple macro to print error message on unintentional error # simple macro to print error message on unintentional error
:set ExitError do={ :set ExitError do={
:local ExitOK [ :tostr $1 ]; :local ExitOK [ :tostr $1 ];
:local ScriptName [ :tostr $2 ]; :local Name [ :tostr $2 ];
:global IfThenElse;
:global LogPrint; :global LogPrint;
:if ($ExitOK = "false") do={ :if ($ExitOK = "false") do={
$LogPrint error $ScriptName ("Script '" . $ScriptName . "' exited with error."); $LogPrint error $Name ([ $IfThenElse ([ :pick $Name 0 1 ] = "\$") \
"Function" "Script" ] . " '" . $Name . "' exited with error.");
} }
} }
@ -1016,7 +1018,7 @@
} }
# install new scripts, update existing scripts # install new scripts, update existing scripts
:set ScriptInstallUpdate do={ :set ScriptInstallUpdate do={ :do {
:local Scripts [ :toarray $1 ]; :local Scripts [ :toarray $1 ];
:local NewComment [ :tostr $2 ]; :local NewComment [ :tostr $2 ];
@ -1235,7 +1237,9 @@
:set GlobalConfigChanges; :set GlobalConfigChanges;
:set GlobalConfigMigration; :set GlobalConfigMigration;
} }
} } on-error={
:global ExitError; $ExitError false $0;
} }
# lock script against multiple invocation # lock script against multiple invocation
:set ScriptLock do={ :set ScriptLock do={
@ -1370,11 +1374,13 @@
} }
# send notification via NotificationFunctions - expects at least two string arguments # send notification via NotificationFunctions - expects at least two string arguments
:set SendNotification do={ :set SendNotification do={ :do {
:global SendNotification2; :global SendNotification2;
$SendNotification2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 }); $SendNotification2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 });
} } on-error={
:global ExitError; $ExitError false $0;
} }
# send notification via NotificationFunctions - expects one array argument # send notification via NotificationFunctions - expects one array argument
:set SendNotification2 do={ :set SendNotification2 do={

View file

@ -10,7 +10,7 @@
:global BridgePortTo; :global BridgePortTo;
:set BridgePortTo do={ :set BridgePortTo do={ :do {
:local BridgePortTo [ :tostr $1 ]; :local BridgePortTo [ :tostr $1 ];
:global IfThenElse; :global IfThenElse;
@ -65,4 +65,6 @@
$LogPrint info $0 ("Re-enabling interfaces..."); $LogPrint info $0 ("Re-enabling interfaces...");
/interface/ethernet/enable $InterfaceReEnable; /interface/ethernet/enable $InterfaceReEnable;
} }
} } on-error={
:global ExitError; $ExitError false $0;
} }

View file

@ -10,7 +10,7 @@
:global BridgePortVlan; :global BridgePortVlan;
:global BridgePortVlan do={ :global BridgePortVlan do={ :do {
:local ConfigTo [ :tostr $1 ]; :local ConfigTo [ :tostr $1 ];
:global IfThenElse; :global IfThenElse;
@ -74,4 +74,6 @@
$LogPrint info $0 ("Re-enabling interfaces..."); $LogPrint info $0 ("Re-enabling interfaces...");
/interface/ethernet/enable $InterfaceReEnable; /interface/ethernet/enable $InterfaceReEnable;
} }
} } on-error={
:global ExitError; $ExitError false $0;
} }

View file

@ -12,11 +12,13 @@
:global InspectVarReturn; :global InspectVarReturn;
# inspect variable and print on terminal # inspect variable and print on terminal
:set InspectVar do={ :set InspectVar do={ :do {
:global InspectVarReturn; :global InspectVarReturn;
:put [ :tocrlf [ $InspectVarReturn $1 ] ]; :put [ :tocrlf [ $InspectVarReturn $1 ] ];
} } on-error={
:global ExitError; $ExitError false $0;
} }
# inspect variable and return formatted string # inspect variable and return formatted string
:set InspectVarReturn do={ :set InspectVarReturn do={

View file

@ -12,7 +12,7 @@
:global IPCalcReturn; :global IPCalcReturn;
# print netmask, network, min host, max host and broadcast # print netmask, network, min host, max host and broadcast
:set IPCalc do={ :set IPCalc do={ :do {
:local Input [ :tostr $1 ]; :local Input [ :tostr $1 ];
:global FormatLine; :global FormatLine;
@ -27,7 +27,9 @@
[ $FormatLine "HostMin" ($Values->"hostmin") ] . "\n" . \ [ $FormatLine "HostMin" ($Values->"hostmin") ] . "\n" . \
[ $FormatLine "HostMax" ($Values->"hostmax") ] . "\n" . \ [ $FormatLine "HostMax" ($Values->"hostmax") ] . "\n" . \
[ $FormatLine "Broadcast" ($Values->"broadcast") ]) ]; [ $FormatLine "Broadcast" ($Values->"broadcast") ]) ];
} } on-error={
:global ExitError; $ExitError false $0;
} }
# calculate and return netmask, network, min host, max host and broadcast # calculate and return netmask, network, min host, max host and broadcast
:set IPCalcReturn do={ :set IPCalcReturn do={

View file

@ -34,7 +34,7 @@
} }
# flush e-mail queue # flush e-mail queue
:set FlushEmailQueue do={ :set FlushEmailQueue do={ :do {
:global EmailQueue; :global EmailQueue;
:global EitherOr; :global EitherOr;
@ -113,7 +113,9 @@
} else={ } else={
/system/scheduler/set interval=1m comment="Waiting for retry..." $Scheduler; /system/scheduler/set interval=1m comment="Waiting for retry..." $Scheduler;
} }
} } on-error={
:global ExitError; $ExitError false $0;
} }
# generate filter for log-forward # generate filter for log-forward
:set LogForwardFilterLogForwarding do={ :set LogForwardFilterLogForwarding do={
@ -224,11 +226,13 @@
} }
# send notification via e-mail - expects at least two string arguments # send notification via e-mail - expects at least two string arguments
:set SendEMail do={ :set SendEMail do={ :do {
:global SendEMail2; :global SendEMail2;
$SendEMail2 ({ origin=$0; subject=$1; message=$2; link=$3 }); $SendEMail2 ({ origin=$0; subject=$1; message=$2; link=$3 });
} } on-error={
:global ExitError; $ExitError false $0;
} }
# send notification via e-mail - expects one array argument # send notification via e-mail - expects one array argument
:set SendEMail2 do={ :set SendEMail2 do={

View file

@ -18,7 +18,7 @@
:global SetupMatrixJoinRoom; :global SetupMatrixJoinRoom;
# flush Matrix queue # flush Matrix queue
:set FlushMatrixQueue do={ :set FlushMatrixQueue do={ :do {
:global MatrixQueue; :global MatrixQueue;
:global IsFullyConnected; :global IsFullyConnected;
@ -57,7 +57,9 @@
/system/scheduler/remove [ find where name="_FlushMatrixQueue" ]; /system/scheduler/remove [ find where name="_FlushMatrixQueue" ];
:set MatrixQueue; :set MatrixQueue;
} }
} } on-error={
:global ExitError; $ExitError false $0;
} }
# send notification via Matrix - expects one array argument # send notification via Matrix - expects one array argument
:set ($NotificationFunctions->"matrix") do={ :set ($NotificationFunctions->"matrix") do={
@ -164,11 +166,13 @@
} }
# send notification via Matrix - expects at least two string arguments # send notification via Matrix - expects at least two string arguments
:set SendMatrix do={ :set SendMatrix do={ :do {
:global SendMatrix2; :global SendMatrix2;
$SendMatrix2 ({ origin=$0; subject=$1; message=$2; link=$3 }); $SendMatrix2 ({ origin=$0; subject=$1; message=$2; link=$3 });
} } on-error={
:global ExitError; $ExitError false $0;
} }
# send notification via Matrix - expects one array argument # send notification via Matrix - expects one array argument
:set SendMatrix2 do={ :set SendMatrix2 do={

View file

@ -15,7 +15,7 @@
:global SendNtfy2; :global SendNtfy2;
# flush ntfy queue # flush ntfy queue
:set FlushNtfyQueue do={ :set FlushNtfyQueue do={ :do {
:global NtfyQueue; :global NtfyQueue;
:global NtfyMessageIDs; :global NtfyMessageIDs;
@ -52,7 +52,9 @@
/system/scheduler/remove [ find where name="_FlushNtfyQueue" ]; /system/scheduler/remove [ find where name="_FlushNtfyQueue" ];
:set NtfyQueue; :set NtfyQueue;
} }
} } on-error={
:global ExitError; $ExitError false $0;
} }
# send notification via ntfy - expects one array argument # send notification via ntfy - expects one array argument
:set ($NotificationFunctions->"ntfy") do={ :set ($NotificationFunctions->"ntfy") do={
@ -132,11 +134,13 @@
} }
# send notification via ntfy - expects at least two string arguments # send notification via ntfy - expects at least two string arguments
:set SendNtfy do={ :set SendNtfy do={ :do {
:global SendNtfy2; :global SendNtfy2;
$SendNtfy2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 }); $SendNtfy2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 });
} } on-error={
:global ExitError; $ExitError false $0;
} }
# send notification via ntfy - expects one array argument # send notification via ntfy - expects one array argument
:set SendNtfy2 do={ :set SendNtfy2 do={

View file

@ -15,7 +15,7 @@
:global SendTelegram2; :global SendTelegram2;
# flush telegram queue # flush telegram queue
:set FlushTelegramQueue do={ :set FlushTelegramQueue do={ :do {
:global TelegramQueue; :global TelegramQueue;
:global TelegramMessageIDs; :global TelegramMessageIDs;
@ -56,7 +56,9 @@
/system/scheduler/remove [ find where name="_FlushTelegramQueue" ]; /system/scheduler/remove [ find where name="_FlushTelegramQueue" ];
:set TelegramQueue; :set TelegramQueue;
} }
} } on-error={
:global ExitError; $ExitError false $0;
} }
# send notification via telegram - expects one array argument # send notification via telegram - expects one array argument
:set ($NotificationFunctions->"telegram") do={ :set ($NotificationFunctions->"telegram") do={
@ -180,11 +182,13 @@
} }
# send notification via telegram - expects at least two string arguments # send notification via telegram - expects at least two string arguments
:set SendTelegram do={ :set SendTelegram do={ :do {
:global SendTelegram2; :global SendTelegram2;
$SendTelegram2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 }); $SendTelegram2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 });
} } on-error={
:global ExitError; $ExitError false $0;
} }
# send notification via telegram - expects one array argument # send notification via telegram - expects one array argument
:set SendTelegram2 do={ :set SendTelegram2 do={

View file

@ -11,7 +11,7 @@
:global ScriptRunOnce; :global ScriptRunOnce;
# fetch and run script(s) once # fetch and run script(s) once
:set ScriptRunOnce do={ :set ScriptRunOnce do={ :do {
:local Scripts [ :toarray $1 ]; :local Scripts [ :toarray $1 ];
:global ScriptRunOnceBaseUrl; :global ScriptRunOnceBaseUrl;
@ -49,4 +49,6 @@
} }
} }
} }
} } on-error={
:global ExitError; $ExitError false $0;
} }

View file

@ -12,7 +12,7 @@
:global SSHKeysImportFile; :global SSHKeysImportFile;
# import single key passed as string # import single key passed as string
:set SSHKeysImport do={ :set SSHKeysImport do={ :do {
:local Key [ :tostr $1 ]; :local Key [ :tostr $1 ];
:local User [ :tostr $2 ]; :local User [ :tostr $2 ];
@ -64,10 +64,12 @@
/file/remove "tmpfs/ssh-keys-import"; /file/remove "tmpfs/ssh-keys-import";
:return false; :return false;
} }
} } on-error={
:global ExitError; $ExitError false $0;
} }
# import keys from a file # import keys from a file
:set SSHKeysImportFile do={ :set SSHKeysImportFile do={ :do {
:local FileName [ :tostr $1 ]; :local FileName [ :tostr $1 ];
:local User [ :tostr $2 ]; :local User [ :tostr $2 ];
@ -106,4 +108,6 @@
$LogPrint warning $0 ("SSH key of type '" . $KeyVal->0 . "' is not supported."); $LogPrint warning $0 ("SSH key of type '" . $KeyVal->0 . "' is not supported.");
} }
} }
} } on-error={
:global ExitError; $ExitError false $0;
} }

View file

@ -25,7 +25,7 @@
:if ([ :len $Scheduler ] = 0) do={ :if ([ :len $Scheduler ] = 0) do={
$LogPrint info $ScriptName ("Creating scheduler _ModeButtonScheduler, counting presses..."); $LogPrint info $ScriptName ("Creating scheduler _ModeButtonScheduler, counting presses...");
:global ModeButtonScheduler do={ :global ModeButtonScheduler do={ :do {
:local FuncName $0; :local FuncName $0;
:global ModeButton; :global ModeButton;
@ -81,7 +81,9 @@
} else={ } else={
$LogPrint info $FuncName ("No action defined for " . $Count . " mode-button presses."); $LogPrint info $FuncName ("No action defined for " . $Count . " mode-button presses.");
} }
} } on-error={
:global ExitError; $ExitError false $0;
} }
/system/scheduler/add name="_ModeButtonScheduler" \ /system/scheduler/add name="_ModeButtonScheduler" \
on-event=":global ModeButtonScheduler; \$ModeButtonScheduler;" interval=3s; on-event=":global ModeButtonScheduler; \$ModeButtonScheduler;" interval=3s;
} else={ } else={