From 44520989388d4b1cebbdc287314756bffff70eb1 Mon Sep 17 00:00:00 2001 From: levasseur Date: Mon, 20 Sep 2021 17:36:42 +0200 Subject: [PATCH] corrected KEEPGOING support, corrected noerror behaviour --- lib/aaa_errors.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/aaa_errors.sh b/lib/aaa_errors.sh index d9cea2e..58ec9d4 100644 --- a/lib/aaa_errors.sh +++ b/lib/aaa_errors.sh @@ -20,6 +20,8 @@ function die() if [[ "$KEEPGOING" != "true" ]] || [[ "$2" == "--force" ]]; then prnt E "Sortie prématuré avec erreur (code #$errorcode)." + # We remove KEEPGOING in case of --force so error() behave correctly + export KEEPGOING=false exit $errorcode else prnt W "On continue malgrés l'erreur #$errorcode." @@ -61,7 +63,17 @@ function error() fi } # Trigger error function on error -trap "error ${LINENO}; backtrace; exit 255" ERR +trap "error ${LINENO}; backtrace; err_exit" ERR + + +# ------------------------------------------------------------------------------ +# Exit program in case of error unless keepgoing is set to true +function err_exit +{ + if [[ $KEEPGOING != true ]]; then + exit 255 + fi +} # ------------------------------------------------------------------------------ @@ -90,7 +102,7 @@ noerror() local noout=true shift fi - + set +o errexit trap - ERR @@ -100,12 +112,12 @@ noerror() $@ fi local code=$? + echo $code trap "error ${LINENO}" ERR set -o errexit - - echo $code } +export -f noerror # ------------------------------------------------------------------------------ @@ -120,5 +132,6 @@ check_root() die 4 --force fi } +export -f check_root # EOF