This commit is contained in:
2025-08-25 07:06:50 +02:00
parent e8d09164ff
commit 581fb0c0f0
15 changed files with 287 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
# Common error handling setup
# set -euo pipefail
SCRIPT="${BASH_SOURCE[-1]}" # last sourced = the actual script file
ERROR_FILE="$SCRIPT.error"
DONE_FILE="$SCRIPT.done"
# Reset markers
rm -f "$ERROR_FILE" "$DONE_FILE"
error_handler() {
local exit_code=$?
local line_no=$1
local cmd="$2"
{
echo "EXIT_CODE=$exit_code"
echo "LINE=$line_no"
echo "COMMAND=$cmd"
} > "$ERROR_FILE"
# If we are inside a sourced script, don't kill the shell
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
return $exit_code
else
exit $exit_code
fi
}
trap 'error_handler ${LINENO} "$BASH_COMMAND"' ERR
mark_done() {
touch "$DONE_FILE"
}