From 0432ea1558b297c8ec4949b8af572c705e55c2f9 Mon Sep 17 00:00:00 2001 From: tteckster Date: Fri, 10 Feb 2023 20:51:53 -0500 Subject: [PATCH] Update haos-vm-v5.sh add new error_handler --- vm/haos-vm-v5.sh | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/vm/haos-vm-v5.sh b/vm/haos-vm-v5.sh index 31728e62..e89c1951 100644 --- a/vm/haos-vm-v5.sh +++ b/vm/haos-vm-v5.sh @@ -37,22 +37,16 @@ HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" THIN="discard=on,ssd=1," -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR trap cleanup EXIT -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - [ ! -z ${VMID-} ] && cleanup_vmid - exit $EXIT +function error_handler() { + local exit_code="$?" + local line_number="$1" + local command="$2" + local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" + echo -e "\n$error_message\n" + cleanup_vmid } function cleanup_vmid() { if qm status $VMID &>/dev/null; then