From bb63e91f32fe7bdb339b2d39b867bd44c7b69d1c Mon Sep 17 00:00:00 2001 From: tteckster Date: Fri, 3 Feb 2023 11:47:41 -0500 Subject: [PATCH] Update magicmirror-v5-install.sh add error_handler --- install/magicmirror-v5-install.sh | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/install/magicmirror-v5-install.sh b/install/magicmirror-v5-install.sh index 5acc38b6..7fad5c70 100644 --- a/install/magicmirror-v5-install.sh +++ b/install/magicmirror-v5-install.sh @@ -14,21 +14,14 @@ CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -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 - -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 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +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" } function msg_info() {