Skip to content

Commit 740bbcf

Browse files
committed
enhance debug functions
the debug function will now show the whole chain of functions the new function can be used to show the stacktrace after an error this is useful as module give output an exit codes both of them get used differently, but at the same time
1 parent 087570d commit 740bbcf

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

runxtb.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,26 @@ fatal ()
7777

7878
debug ()
7979
{
80-
# Include the fuction that called the debug statement (hence index 1, as 0 would be the debug function itself)
80+
# Include the fuction that called the debug statement (skip the first, that is the debug function itself)
8181
local line
8282
while read -r line || [[ -n "$line" ]] ; do
83-
echo "DEBUG : (${FUNCNAME[1]}) $line" >&4
83+
echo "DEBUG : (${FUNCNAME[*]:1}) $line" >&4
8484
done <<< "$*"
8585
}
8686

87+
debug_trace ()
88+
{
89+
# This function will read from stdout and pass it to the debug function.
90+
# The intended funktionality is within this construct:
91+
# command_that_fails_and_writes_stdout > >(debug_trace) || fatal "fail"
92+
# The script error message comes first, but the command output comes next.
93+
# It's a helper function for the modules feature.
94+
local line
95+
while read -r line || [[ -n "$line" ]] ; do
96+
debug "$line"
97+
done
98+
}
99+
87100
#
88101
# Print some helping commands
89102
# The lines are distributed throughout the script and grepped for

0 commit comments

Comments
 (0)