#
# Note: It does not show function args unless you first run:
# shopt -s extdebug
- # err-catch runs this for you.
+ # which err-catch & err-print does for you.
+ #
+ # $1 is the frame to start printing on. default -1. Useful when
+ # printing from an ERR trap function.
local -i argc_index=0 frame i start=${1:-1} max_indent=8 indent
local source
err=$?
exec >&2
set +x
- echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}:in \`$BASH_COMMAND' returned $err"
- # err trap does not work within an error trap, the following line:
- err-bash-trace 2; set -e
+ echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: \`$BASH_COMMAND' returned $err"
+ err-bash-trace 2
+ set -e # err trap does not work within an error trap
"${_errcatch_cleanup[@]:-:}" # note :-: is to be compatible with set -u
echo "$0: exiting with code $err"
exit $err
set -o pipefail
}
+err-print() {
+ # help: on errors: print stack trace
+ #
+ # This function depends on err-bash-trace.
+
+ set -E; shopt -s extdebug
+ _err-trap() {
+ err=$?
+ exec >&2
+ set +x
+ echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: \`$BASH_COMMAND' returned $err"
+ err-bash-trace 2
+ }
+ trap _err-trap ERR
+ set -o pipefail
+}
+
+
err-exit() {
# usage: err-exit [EXIT_CODE] [MESSAGE]
# help: exit and print stack trace.