mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-09-07 14:11:52 +00:00
Print the function stack on param error in testlib
Most of the functions of the test library include some type of parameter validation, when a function is called and one of its parameters don't comply with the expected parameters it terminates the whole script. This is expected, but sometimes it can be difficult to figure out what was the function that received the incorrect parameters in the script. This commit adds a function that prints a stack of the function calls so when a script is terminated it is easier to figure out the culprit.
This commit is contained in:
committed by
Matthew Johnson
parent
4faee3855f
commit
d9c47bb4af
@@ -58,6 +58,18 @@ generate_random_name() {
|
||||
|
||||
}
|
||||
|
||||
print_stack() {
|
||||
|
||||
echo "An error occurred"
|
||||
echo "Function stack (most recent on top):"
|
||||
for func in ${FUNCNAME[*]}; do
|
||||
if [ "$func" != "print_stack" ] && [ "$func" != "terminate" ]; then
|
||||
echo -e "\\t$func"
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
terminate() {
|
||||
|
||||
# since the library could be sourced and run from an interactive shell
|
||||
@@ -67,8 +79,10 @@ terminate() {
|
||||
local msg=$1
|
||||
local param
|
||||
case "$-" in
|
||||
*i*) : ${param:?"$msg, exiting..."} ;;
|
||||
*) echo "$msg, exiting..."
|
||||
*i*) print_stack
|
||||
: "${param:?"$msg, exiting..."}" ;;
|
||||
*) print_stack
|
||||
echo "$msg, exiting..."
|
||||
exit 1;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user