fix: Catch unexpected failures (#140)

Signed-off-by: Tarik Megzari <tarik.megzari@corp.ovh.com>

Co-authored-by: Tarik Megzari <tarik.megzari@corp.ovh.com>
This commit is contained in:
Tarik Megzari
2022-01-31 15:38:38 +01:00
committed by GitHub
parent 17d272420a
commit bb03764918
2 changed files with 21 additions and 0 deletions

View File

@ -103,6 +103,20 @@ debug() {
if [ "$MACHINE_LOG_LEVEL" -ge 5 ]; then _logger "$GRAY" "[DBG ] $*"; fi
}
exception() {
# Trap exit code is the same as the trapped one unless we call an explicit exit
TRAP_CODE=$?
if [ "$ACTIONS_DONE" -ne 1 ]; then
if [ "$BATCH_MODE" -eq 1 ]; then
BATCH_OUTPUT="KO $SCRIPT_NAME $BATCH_OUTPUT KO{Unexpected exit code: $TRAP_CODE}"
becho "$BATCH_OUTPUT"
else
crit "Check failed with unexpected exit code: $TRAP_CODE"
fi
exit 1 # Means critical status
fi
}
#
# sudo wrapper
# issue crit state if not allowed to perform sudo