corrected KEEPGOING support, corrected noerror behaviour

This commit is contained in:
levasseur
2021-09-20 17:36:42 +02:00
parent 436fd98625
commit d3c7b80030

View File

@@ -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
}
# ------------------------------------------------------------------------------
@@ -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