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-04-13 02:43:50 -05:00
parent ba68231273
commit 12354b8eb5
2 changed files with 25 additions and 1 deletions

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
}

View file

@ -100,6 +100,8 @@ with pkgs;
diffPlugins = (callPackage ../build-support/plugins.nix {}).diffPlugins;
dieHook = makeSetupHook {} ../build-support/setup-hooks/die.sh;
dockerTools = callPackage ../build-support/docker { };
docker_compose = pythonPackages.docker_compose;
@ -287,7 +289,8 @@ with pkgs;
inherit contents compressor prepend;
};
makeWrapper = makeSetupHook { } ../build-support/setup-hooks/make-wrapper.sh;
makeWrapper = makeSetupHook { deps = [ dieHook ]; }
../build-support/setup-hooks/make-wrapper.sh;
makeModulesClosure = { kernel, rootModules, allowMissing ? false }:
callPackage ../build-support/kernel/modules-closure.nix {