global-functions: introduce $ExitOnError

This is just like $ExitError, but first parameter is dropped. We will
not need it now that we can exit a script with :exit.
This commit is contained in:
Christian Hesse 2026-01-20 10:31:51 +01:00
parent 9347063647
commit bbf2f5abbf

View file

@ -36,6 +36,7 @@
:global EitherOr;
:global EscapeForRegEx;
:global ExitError;
:global ExitOnError;
:global FetchHuge;
:global FetchUserAgentStr;
:global FileExists;
@ -489,6 +490,19 @@
}
}
# simple macro to print error message on unintentional error
:set ExitOnError do={
:local Name [ :tostr $1 ];
:local Error [ :tostr $2 ];
:global IfThenElse;
:global LogPrint;
$LogPrint error $Name ([ $IfThenElse ([ :pick $Name 0 1 ] = "\$") \
"Function" "Script" ] . " '" . $Name . "' exited with error" . \
[ $IfThenElse (!($Error ~ "^(|true|false)\$")) (": " . $Error) "." ]);
}
# fetch huge data to file, read in chunks
:set FetchHuge do={
:local ScriptName [ :tostr $1 ];