Files
DynastyRevolution-Scripts/core/error_handler.func

21 lines
491 B
Bash

#!/usr/bin/env bash
error_handler() {
local exit_code="$?"
local line_number="$1"
local command="$2"
if [[ $exit_code -ne 0 ]]; then
msg_error "Manifestation Failure on Line $line_number"
if [[ -n "${CTID:-}" ]]; then
pct stop "$CTID" >/dev/null 2>&1
pct destroy "$CTID" >/dev/null 2>&1
msg_warn "Orphaned container $CTID purged."
fi
exit $exit_code
fi
}
catch_errors() {
set -Eeuo pipefail
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
}