diff --git a/bin/bash-back b/bin/bash-back index 1851702..c7bdcf8 100755 --- a/bin/bash-back +++ b/bin/bash-back @@ -9,7 +9,7 @@ SCRIPT=$1 function on_return { if [[ "${BASH_COMMAND}" == return* ]]; then - code=$(echo "${BASH_COMMAND}" | cut -d' ' -f2) # regex does not work here! + code=$(echo "${BASH_COMMAND}" | cut -d' ' -f2) # regex does not work here unfortunately! thus use of basic cut if [[ -n "$code" ]] && [[ $code -ne 0 ]]; then trap - DEBUG >&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: return $code from ${FUNCNAME[1]}" @@ -20,11 +20,8 @@ function on_return { # overridden function which permits stacktracing of original `return` statement function exit { code=${1:-0} - - # TODO: prefer this output, but change the exit case scenario message in stacktrace first! - # >&2 echo "${BASH_SOURCE[2]}:${BASH_LINENO[0]} exit $@" - - >&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: exit $@" + >&2 echo "${BASH_SOURCE[2]}:${BASH_LINENO[0]} exit $@" + # >&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: exit $@" builtin exit $code } @@ -60,8 +57,9 @@ function on_exit { last_error=$(tail -n1 $TMP_ERROR) last_source=${stack_sources[0]} last_source=${last_source//./"\."} # replace . by \. - regex="^$last_source: line ([0-9]+): (.*)\$" - if [[ "$last_error" =~ $regex ]]; then + regex1="^$last_source: line ([0-9]+): (.*)\$" + regex2="^$last_source:([0-9]+) (.*)\$" + if [[ "$last_error" =~ $regex1 || "$last_error" =~ $regex2 ]]; then line=${BASH_REMATCH[1]} message=${BASH_REMATCH[2]} regex=': unbound variable$' @@ -78,7 +76,7 @@ function on_exit { >&4 echo -e "ERROR $code: [$message]" else - >&4 echo "ERROR $code: " + >&4 echo "ERROR $code: " fi for i in "${!stack_functions[@]}"; do diff --git a/lib/utility.bash b/lib/utility.bash index 32eee46..092c863 100644 --- a/lib/utility.bash +++ b/lib/utility.bash @@ -4,9 +4,9 @@ function blabla { } function suite { + echo $nope exit 10 # youpi exit - echo $nope command_not_found return 7 return