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
:set ExitError do={
:local ExitOK [ :tostr $1 ];
:local ScriptName [ :tostr $2 ];
:local ExitOK [ :tostr $1 ];
:local Name [ :tostr $2 ];
:global IfThenElse;
:global LogPrint;
: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
:set ScriptInstallUpdate do={
:set ScriptInstallUpdate do={ :do {
:local Scripts [ :toarray $1 ];
:local NewComment [ :tostr $2 ];
@ -1235,7 +1237,9 @@
:set GlobalConfigChanges;
:set GlobalConfigMigration;
}
}
} on-error={
:global ExitError; $ExitError false $0;
} }
# lock script against multiple invocation
:set ScriptLock do={
@ -1370,11 +1374,13 @@
}
# send notification via NotificationFunctions - expects at least two string arguments
:set SendNotification do={
:set SendNotification do={ :do {
:global SendNotification2;
$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
:set SendNotification2 do={

View file

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

View file

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

View file

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

View file

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

View file

@ -34,7 +34,7 @@
}
# flush e-mail queue
:set FlushEmailQueue do={
:set FlushEmailQueue do={ :do {
:global EmailQueue;
:global EitherOr;
@ -113,7 +113,9 @@
} else={
/system/scheduler/set interval=1m comment="Waiting for retry..." $Scheduler;
}
}
} on-error={
:global ExitError; $ExitError false $0;
} }
# generate filter for log-forward
:set LogForwardFilterLogForwarding do={
@ -224,11 +226,13 @@
}
# send notification via e-mail - expects at least two string arguments
:set SendEMail do={
:set SendEMail do={ :do {
:global SendEMail2;
$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
:set SendEMail2 do={

View file

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

View file

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

View file

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

View file

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

View file

@ -12,7 +12,7 @@
:global SSHKeysImportFile;
# import single key passed as string
:set SSHKeysImport do={
:set SSHKeysImport do={ :do {
:local Key [ :tostr $1 ];
:local User [ :tostr $2 ];
@ -64,10 +64,12 @@
/file/remove "tmpfs/ssh-keys-import";
:return false;
}
}
} on-error={
:global ExitError; $ExitError false $0;
} }
# import keys from a file
:set SSHKeysImportFile do={
:set SSHKeysImportFile do={ :do {
:local FileName [ :tostr $1 ];
:local User [ :tostr $2 ];
@ -106,4 +108,6 @@
$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={
$LogPrint info $ScriptName ("Creating scheduler _ModeButtonScheduler, counting presses...");
:global ModeButtonScheduler do={
:global ModeButtonScheduler do={ :do {
:local FuncName $0;
:global ModeButton;
@ -81,7 +81,9 @@
} else={
$LogPrint info $FuncName ("No action defined for " . $Count . " mode-button presses.");
}
}
} on-error={
:global ExitError; $ExitError false $0;
} }
/system/scheduler/add name="_ModeButtonScheduler" \
on-event=":global ModeButtonScheduler; \$ModeButtonScheduler;" interval=3s;
} else={