dieHook: Add die utility function

Calling `die "Error message"` causes the current script to exit with
an error, printing a backtrace
This commit is contained in:
Taahir Ahmed
2017-08-08 00:17:56 -05:00
parent ba68231273
commit 12354b8eb5
2 changed files with 25 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
# Exit with backtrace and error message
#
# Usage: die "Error message"
die() {
# Let us be a little sloppy with errors, because otherwise the final
# invocation of `caller` below will cause the script to exit.
set +e
# Print our error message
printf "\nBuilder called die: %b\n" "$*"
printf "Backtrace:\n"
# Print a backtrace.
local frame=0
while caller $frame; do
((frame++));
done
printf "\n"
exit 1
}