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 ];