error tracing

This commit is contained in:
James Barnett 2017-05-31 12:59:48 -04:00
parent e6d48a89ad
commit a6e0cd3287
No known key found for this signature in database
GPG key ID: E4B5E45AA3B8C5C3

View file

@ -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"