diff options
-rw-r--r-- | jenkins-helpers.sh | 21 | ||||
-rwxr-xr-x | tcwg_bmk-build.sh | 2 | ||||
-rwxr-xr-x | tcwg_gnu-build.sh | 2 |
3 files changed, 23 insertions, 2 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh index 83f950ae..b196edca 100644 --- a/jenkins-helpers.sh +++ b/jenkins-helpers.sh @@ -1302,3 +1302,24 @@ EOF run_step_prev_step="$pretty_step" } + +# Print Python style traceback from a trap EXIT +# More readable version of running "caller" +print_traceback () +{ + echo "ERROR Traceback (most recent call last):" + # Show most recent calls last + # >=1 to skip the trap handler entry + # Start from end-2 to skip the top level "main" entry + # which isn't useful + for (( i=${#FUNCNAME[@]}-2 ; i>=1 ; i-- )) ; do + source_file=${BASH_SOURCE[$i+1]} + line_no=${BASH_LINENO[$i]} + echo " File: $source_file, line $line_no" + # Remove leading whitespace to keep indentation readable + echo " $(sed -e "${line_no}!d" -e 's/^[[:space:]]*//' "$source_file")" + done + # We don't know the line number of the exit itself when we trap EXIT + echo " File: ${BASH_SOURCE[0]}, line ${BASH_LINENO[0]}" + echo " (trap handler, 'exit' call line is unknown)" +} diff --git a/tcwg_bmk-build.sh b/tcwg_bmk-build.sh index bd66fe67..39dc474d 100755 --- a/tcwg_bmk-build.sh +++ b/tcwg_bmk-build.sh @@ -108,7 +108,7 @@ verbose2="${verbose2-false}" if $verbose2; then set -x; fi -trap "eval \"echo ERROR at \${FUNCNAME[0]}:\${BASH_LINENO[0]}\"" EXIT +trap print_traceback EXIT # Set start and finish steps for different modes. default_start_at="" diff --git a/tcwg_gnu-build.sh b/tcwg_gnu-build.sh index f88c8e81..24c5c44c 100755 --- a/tcwg_gnu-build.sh +++ b/tcwg_gnu-build.sh @@ -64,7 +64,7 @@ verbose2="${verbose2-false}" if $verbose2; then set -x; fi -trap "eval \"echo ERROR at \${FUNCNAME[0]}:\${BASH_LINENO[0]}\"" EXIT +trap print_traceback EXIT # Set start and finish steps for different modes. default_start_at="" |