From bbf2f5abbf280b2ff7c420838eb9e95cf8100338 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 20 Jan 2026 10:31:51 +0100 Subject: [PATCH] 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. --- global-functions.rsc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/global-functions.rsc b/global-functions.rsc index 7c40632c..34125892 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -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 ];