From a6e0cd32870562868539ebf79dbddffd329b588f Mon Sep 17 00:00:00 2001 From: James Barnett Date: Wed, 31 May 2017 12:59:48 -0400 Subject: [PATCH] error tracing --- scripts/snap-pac | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index d3ad10b..767689d 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -18,6 +18,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +set -o errtrace + declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper declare -r DESC_LIMIT=48 declare -r name="snap-pac" @@ -28,12 +30,21 @@ declare -r pre_or_post=$1 out() { printf "$1 $2\n" "${@:3}"; } error() { out "==> \033[00;31merror:\033[00m" "$@"; } >&2 die() { - error "$@" [[ $PACMAN_ABORT_ON_FAIL == "no" ]] && exit 0 exit 1 } -error_exit() { die "Aborted due to error."; } -kill_exit() { die "\nExited due to user intervention."; } +trapkill() { + error "Exited due to user intervention." + die +} +traperror() { + error "Exited due to error on line $1" + out "exit status:" "$2" + out "command:" "$3" + out "bash line:" "$4" + out "function name:" "$5" + die +} truncate_description() { desc="$@" @@ -52,8 +63,8 @@ set_defaults() { PACMAN_CLEANUP_ALGORITHM="number" } -trap error_exit ERR -trap kill_exit SIGTERM SIGINT +trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR +trap trapkill SIGTERM SIGINT source "$SNAPPER_CONFIG_FILE"