-
-
Save zachriggle/8574964d2e3078cdfae84b5744a9d4dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
source TRAPERR.zsh | |
a() { | |
b | |
} | |
b() { | |
c | |
} | |
c() { | |
d | |
} | |
d() { | |
false | |
} | |
a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
_err() { | |
echo "${fg[red]}$@${reset_color}" | |
} | |
# Do not set TRAPERR if we are in an interactive shell | |
if [[ "$ZSH_ARGZERO" != "-zsh" ]]; then | |
TRAPERR() { | |
# If we are in a $() subshell, do not emit an error message, since | |
# it will just get duplicated when the result is an error code | |
if [ "$ZSH_SUBSHELL" -gt 0 ]; then | |
return | |
fi | |
# Dump the stack trace | |
_err "An error occurred on ${funcfiletrace[1]}" | |
local i=1 | |
for trace in "${(Oa)funcfiletrace[@]}"; do | |
local err_file=${trace%%:*} | |
local err_line=${trace##*:} | |
_err "Frame $i (${err_file}:$err_line)" | |
if ! [ -f "$err_file" ]; then | |
true | |
else | |
awk 'NR>L-4 && NR<L+4 { printf "%-5d%4s%s\n",NR,(NR==L?">>> ":""),$0 }' "L=$err_line" "$err_file" | |
fi | |
echo | |
i=$(($i+1)) | |
done >&2 | |
} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment