diff --git a/bin/bash-back b/bin/bash-back index b46c359..199784d 100755 --- a/bin/bash-back +++ b/bin/bash-back @@ -65,19 +65,21 @@ function on_exit { regex=': unbound variable$' [[ $code == 1 ]] && [[ "$message" =~ $regex ]] && stack_lines[0]=$line - regex="^return [0-9]* from (.*)\$" + regex="^return ([0-9]*) from (.*)\$" if [[ "$message" =~ $regex ]]; then - funcname="${BASH_REMATCH[1]}" + return_code="${BASH_REMATCH[1]}" + funcname="${BASH_REMATCH[2]}" # >&4 echo "RETURN DETECTED line ${stack_sources[0]} $line $funcname" stack_sources=("${stack_sources[0]}" "${stack_sources[@]}") stack_lines=("$line" "${stack_lines[@]}") stack_functions=("$funcname" "${stack_functions[@]}") + stack_summary+=("ERROR $code: [return $return_code]") + else + stack_summary+=("ERROR $code: [$message]") fi - stack_summary+=("ERROR $code: [$message]") else - # TODO: if last_error is a detected stacktrace, grab as so - # pstree -as $$ => parent contains bash-back? - stack_summary+=("ERROR $code: ") + regex=' .*:[0-9]* .*' + [[ "$last_error" =~ $regex ]] || stack_summary+=("ERROR $code: ") fi for i in "${!stack_functions[@]}"; do diff --git a/lib/utility.bash b/lib/utility.bash index 2eceef9..7f42be1 100755 --- a/lib/utility.bash +++ b/lib/utility.bash @@ -8,12 +8,12 @@ function blabla { } function suite { - command_not_found echo $nope - return + exit return 7 exit 10 # youpi - exit + command_not_found + return } blabla diff --git a/useless.sh b/useless.sh index 9ff73b8..df57f24 100755 --- a/useless.sh +++ b/useless.sh @@ -31,8 +31,8 @@ function F3 { echo start of useless F3 +. lib/utility.bash lib/utility.bash -# . lib/utility.bash # >&2 echo some trace in stderr main