diff options
author | david <public@beloved.name> | 2018-07-17 06:25:00 +0200 |
---|---|---|
committer | david <public@beloved.name> | 2018-07-17 06:25:00 +0200 |
commit | 3aa358cf718f8fc15952757cd04489b26770ac74 (patch) | |
tree | 6a5b913ea072c31b9724afef8aa136ba9c7ea06f | |
parent | 756e4c987b69c6d0ba01c076fdbb326a878cf911 (diff) |
Updated the err file
-rwxr-xr-x | addons.mozilla.org-fsd/get-data/err | 19 | ||||
-rwxr-xr-x | err | 19 |
2 files changed, 22 insertions, 16 deletions
diff --git a/addons.mozilla.org-fsd/get-data/err b/addons.mozilla.org-fsd/get-data/err index 5b501ce..97b3cc3 100755 --- a/addons.mozilla.org-fsd/get-data/err +++ b/addons.mozilla.org-fsd/get-data/err @@ -14,7 +14,6 @@ # limitations under the License. - # Commentary: Bash stack trace and error handling functions. This file # is meant to be sourced. It loads some functions which you may want to # call manually (see the comments at the start of each one), and then @@ -24,6 +23,7 @@ err-allow() { # help: turn off exit and stack trace on error. undoes err-catch set +E +o pipefail; trap ERR } + err-bash-trace() { # help: print stack trace # @@ -46,7 +46,7 @@ err-bash-trace() { fi indent=$((frame-start+1)) indent=$((indent < max_indent ? indent : max_indent)) - printf "%${indent}s↳%sin \`%s" '' "$source" "${FUNCNAME[frame]}" + printf "%${indent}s↳%sin \`%s" '' "$source" "${FUNCNAME[frame]}" if $extdebug; then for ((i=argc_index-1; i >= argc_index-argc; i--)); do printf " %s" "${BASH_ARGV[i]}" @@ -55,10 +55,11 @@ err-bash-trace() { echo \' done } + err-catch() { - # help: print stack trace and exit on error. + # help: on errors: print stack trace and exit # - # Set "${_errcatch_cleanup[@]}" to set a command which will run before exiting. + # You can set "${_errcatch_cleanup[@]}" to a command and it will run before exiting. # This function depends on err-bash-trace. set -E; shopt -s extdebug @@ -69,13 +70,14 @@ err-catch() { 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 - "${_errcatch_cleanup[@]}" + "${_errcatch_cleanup[@]:-}" # note :- is to be compatible with set -u echo "$0: exiting with code $err" exit $err } trap _err-trap ERR set -o pipefail } + err-exit() { # usage: err-exit [EXIT_CODE] [MESSAGE] # help: exit and print stack trace. @@ -87,14 +89,14 @@ err-exit() { exec >&2 code=1 - if [[ $* ]]; then + if [[ "$*" ]]; then if [[ ${1/[^0-9]/} == "$1" ]]; then code=$1 if [[ $2 ]]; then - printf "%s\n" "$2" + printf '%s\n' "$2" fi else - printf "%s\n" "$0: $1" + printf '%s\n' "$0: $1" fi fi echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}" @@ -102,4 +104,5 @@ err-exit() { echo "$0: exiting with code $code" exit $err } + err-catch @@ -14,7 +14,6 @@ # limitations under the License. - # Commentary: Bash stack trace and error handling functions. This file # is meant to be sourced. It loads some functions which you may want to # call manually (see the comments at the start of each one), and then @@ -24,6 +23,7 @@ err-allow() { # help: turn off exit and stack trace on error. undoes err-catch set +E +o pipefail; trap ERR } + err-bash-trace() { # help: print stack trace # @@ -46,7 +46,7 @@ err-bash-trace() { fi indent=$((frame-start+1)) indent=$((indent < max_indent ? indent : max_indent)) - printf "%${indent}s↳%sin \`%s" '' "$source" "${FUNCNAME[frame]}" + printf "%${indent}s↳%sin \`%s" '' "$source" "${FUNCNAME[frame]}" if $extdebug; then for ((i=argc_index-1; i >= argc_index-argc; i--)); do printf " %s" "${BASH_ARGV[i]}" @@ -55,10 +55,11 @@ err-bash-trace() { echo \' done } + err-catch() { - # help: print stack trace and exit on error. + # help: on errors: print stack trace and exit # - # Set "${_errcatch_cleanup[@]}" to set a command which will run before exiting. + # You can set "${_errcatch_cleanup[@]}" to a command and it will run before exiting. # This function depends on err-bash-trace. set -E; shopt -s extdebug @@ -69,13 +70,14 @@ err-catch() { 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 - "${_errcatch_cleanup[@]}" + "${_errcatch_cleanup[@]:-}" # note :- is to be compatible with set -u echo "$0: exiting with code $err" exit $err } trap _err-trap ERR set -o pipefail } + err-exit() { # usage: err-exit [EXIT_CODE] [MESSAGE] # help: exit and print stack trace. @@ -87,14 +89,14 @@ err-exit() { exec >&2 code=1 - if [[ $* ]]; then + if [[ "$*" ]]; then if [[ ${1/[^0-9]/} == "$1" ]]; then code=$1 if [[ $2 ]]; then - printf "%s\n" "$2" + printf '%s\n' "$2" fi else - printf "%s\n" "$0: $1" + printf '%s\n' "$0: $1" fi fi echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}" @@ -102,4 +104,5 @@ err-exit() { echo "$0: exiting with code $code" exit $err } + err-catch |