summaryrefslogtreecommitdiff
path: root/jenkins-helpers.sh
diff options
context:
space:
mode:
authorDavid Spickett <david.spickett@linaro.org>2020-05-15 17:02:55 +0100
committerDavid Spickett <david.spickett@linaro.org>2020-05-18 10:37:32 +0000
commita792a1d55fd28fab9b79ba8d1f8d336a4840e181 (patch)
tree905948d56395489e04a40533bf645cf26146406b /jenkins-helpers.sh
parentdcc16d9eaae5ba56f999e1dc2a101abf6ad92ca8 (diff)
tcwg_bmk-build/tcwg_gnu-build: Add traceback printing
The line number you get from the previous message is confusing. For example: ERROR at run_step:524 Means that something in the function run_step, which was called from line 524, called exit. Instead, add a Python style traceback that shows the call stack with file, line and the content of that line. (though unfortunatley we can't get the line no. of the exit itself) Example traceback: ERROR Traceback (most recent call last): File: /tmp/foo.sh, line 37 foo # hey! File: /tmp/foo.sh, line 32 bar # hi there File: /tmp/foo.sh, line 1 (trap handler, 'exit' call line is unknown) Change-Id: Id6a2734e2b5ef74d05cd51cdbde9a95e5d5a4b44
Diffstat (limited to 'jenkins-helpers.sh')
-rw-r--r--jenkins-helpers.sh21
1 files changed, 21 insertions, 0 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)"
+}