|
|
|
@ -74,7 +74,7 @@ function on_return { |
|
|
|
failure_type="RETURN" |
|
|
|
failure_payload="${FUNCNAME[0]}" |
|
|
|
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}" "${failure_payload}" |
|
|
|
miaou_debug "<on_return code=$failure_code payload=$failure_payload />" |
|
|
|
miaou_debug "<on_return code=$failure_code payload=$failure_payload/>" |
|
|
|
fi |
|
|
|
true |
|
|
|
} |
|
|
|
@ -95,7 +95,7 @@ function exit { |
|
|
|
failure_type="EXIT" |
|
|
|
failure_payload="${error_funcname[0]}" |
|
|
|
|
|
|
|
miaou_debug "<exit code=$failure_code overridden />" |
|
|
|
miaou_debug "<exit code=$failure_code overridden/>" |
|
|
|
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}" "${failure_payload}" |
|
|
|
builtin exit "$failure_code" |
|
|
|
} |
|
|
|
@ -147,9 +147,9 @@ function on_error { |
|
|
|
error_funcname=("${error_funcname[@]}") |
|
|
|
|
|
|
|
if [[ -v failure_payload ]]; then |
|
|
|
miaou_debug "</on_error exit=$failure_code type=${failure_type} payload={${failure_payload}} >" |
|
|
|
miaou_debug "</on_error exit=$failure_code type=${failure_type} payload={${failure_payload}}>" |
|
|
|
else |
|
|
|
miaou_debug "</on_error exit=$failure_code type=${failure_type} >" |
|
|
|
miaou_debug "</on_error exit=$failure_code type=${failure_type}>" |
|
|
|
fi |
|
|
|
|
|
|
|
builtin exit "$failure_code" |
|
|
|
@ -163,6 +163,7 @@ function on_error { |
|
|
|
function on_pipe { |
|
|
|
trap - RETURN |
|
|
|
local tmp_error regex source lineno |
|
|
|
miaou_debug "<on_pipe sub_pid=$BASHPID pid=$$>" |
|
|
|
|
|
|
|
error_source=("${BASH_SOURCE[@]}") |
|
|
|
error_lineno=("${BASH_LINENO[@]}") |
|
|
|
@ -171,7 +172,8 @@ function on_pipe { |
|
|
|
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]' |
|
|
|
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]' |
|
|
|
|
|
|
|
mapfile -t tmp_error <"$MIAOU_BASH_ERROR" |
|
|
|
miaou_debug '<load_tmp_error/>' && mapfile -t tmp_error <"$MIAOU_BASH_ERROR" |
|
|
|
|
|
|
|
last_error="${tmp_error[-1]}" |
|
|
|
regex='^(.*): line ([0-9]+): miaou_error: SUBSHELL_ERROR ([0-9]+) payload: (.*)$' |
|
|
|
if [[ $last_error =~ $regex ]]; then |
|
|
|
@ -187,7 +189,7 @@ function on_pipe { |
|
|
|
failure_code=141 |
|
|
|
failure_type="PIPE_ERROR" |
|
|
|
fi |
|
|
|
miaou_debug "<on_pipe code=$failure_code sub_pid=$BASHPID pid=$$ />" |
|
|
|
miaou_debug "</on_pipe/>" |
|
|
|
builtin exit "$failure_code" |
|
|
|
} |
|
|
|
|
|
|
|
@ -225,7 +227,7 @@ function dump_failure { |
|
|
|
} |
|
|
|
|
|
|
|
function dump_stacktrace { |
|
|
|
miaou_debug "<stacktrace count=${#error_source[@]} >" |
|
|
|
miaou_debug "<stacktrace count=${#error_source[@]}>" |
|
|
|
local i source lineno funcname |
|
|
|
for i in "${!error_source[@]}"; do |
|
|
|
tty_ansi FG_MAGENTA |
|
|
|
@ -247,15 +249,17 @@ function on_exit { |
|
|
|
trap - RETURN |
|
|
|
local code="${1:-0}" last_error regex |
|
|
|
|
|
|
|
miaou_debug "<on_exit code=$code >" |
|
|
|
miaou_debug "<on_exit code=$code>" |
|
|
|
|
|
|
|
[[ ! -v tmp_error ]] && mapfile -t tmp_error <"$MIAOU_BASH_ERROR" |
|
|
|
[[ ! -v tmp_error ]] && |
|
|
|
miaou_debug '<load_tmp_error/>' && |
|
|
|
mapfile -t tmp_error <"$MIAOU_BASH_ERROR" |
|
|
|
|
|
|
|
if [[ -v failure_type && "$failure_type" == 'RETURN' ]]; then |
|
|
|
last_error="${tmp_error[-1]}" |
|
|
|
regex='^(.*): line ([0-9]+): miaou_error: RETURN [0-9]+' |
|
|
|
if [[ "$last_error" =~ $regex ]]; then |
|
|
|
miaou_debug "<return code=$code />" |
|
|
|
miaou_debug "<return code=$code/>" |
|
|
|
local source line |
|
|
|
source="${BASH_REMATCH[1]}" |
|
|
|
line="${BASH_REMATCH[2]}" |
|
|
|
@ -263,24 +267,21 @@ function on_exit { |
|
|
|
error_lineno=("$line" "${error_lineno[@]}") |
|
|
|
error_funcname=("$failure_payload" "${error_funcname[@]}") |
|
|
|
else |
|
|
|
miaou_debug "<return type=unexpected />" |
|
|
|
miaou_debug "<return type=unexpected/>" |
|
|
|
fi |
|
|
|
|
|
|
|
else |
|
|
|
if [[ $code -gt 0 && ${#tmp_error[@]} -gt 0 ]]; then |
|
|
|
last_error="${tmp_error[-1]}" |
|
|
|
miaou_debug "<on_exit_tmp_error last={$last_error} >" |
|
|
|
miaou_debug "<on_exit_tmp_error last={$last_error}>" |
|
|
|
if [[ $code -eq 1 ]]; then |
|
|
|
regex='^(.*): line ([0-9]+): (.*): unbound variable$' |
|
|
|
if [[ "$last_error" =~ $regex ]]; then |
|
|
|
local source line payload |
|
|
|
|
|
|
|
source="${BASH_REMATCH[1]}" |
|
|
|
line="${BASH_REMATCH[2]}" |
|
|
|
payload="${BASH_REMATCH[3]}" |
|
|
|
miaou_debug "<unbound_variable source=${source} line=${line} payload={${payload}} >" |
|
|
|
failure_code=$code |
|
|
|
failure_type='UNBOUND_VARIABLE' |
|
|
|
failure_payload="${BASH_REMATCH[3]}" |
|
|
|
error_source=("${BASH_SOURCE[@]}") |
|
|
|
error_lineno=("${BASH_LINENO[@]}") |
|
|
|
error_funcname=("${FUNCNAME[@]}") |
|
|
|
@ -290,6 +291,11 @@ function on_exit { |
|
|
|
error_source=("$source" "${error_source[@]}") |
|
|
|
error_lineno=("$line" "${error_lineno[@]}") |
|
|
|
error_funcname=("${error_funcname[@]}" '<main>') |
|
|
|
|
|
|
|
failure_code=$code |
|
|
|
failure_type='UNBOUND_VARIABLE' |
|
|
|
failure_payload=$payload |
|
|
|
miaou_debug "<unbound_variable source=${source} line=${line} payload={${failure_payload}}>" |
|
|
|
fi |
|
|
|
fi |
|
|
|
miaou_debug "</on_exit_tmp_error>" |
|
|
|
@ -302,9 +308,9 @@ function on_exit { |
|
|
|
2>&3 >&4 dump_stacktrace |
|
|
|
fi |
|
|
|
if [[ $code -gt 0 ]]; then |
|
|
|
miaou_debug "</on_exit exit=$code >" |
|
|
|
miaou_debug "</on_exit exit=$code>" |
|
|
|
else |
|
|
|
miaou_debug "</on_exit success >" |
|
|
|
miaou_debug "</on_exit success>" |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
@ -325,6 +331,6 @@ trap 'on_return' RETURN |
|
|
|
if [[ -e /proc/$$/fd/3 ]]; then exec 4>&3 3>&-; else exec 4>/dev/tty; fi # swap fd 3 4 when fd 3 sent off |
|
|
|
exec 3>/dev/stderr 2>"$MIAOU_BASH_ERROR" |
|
|
|
|
|
|
|
miaou_debug "<source from=$BASH_ARGV0 pid=${BASHPID} />" |
|
|
|
miaou_debug "<source from=$BASH_ARGV0 pid=${BASHPID}/>" |
|
|
|
# shellcheck source=/dev/null |
|
|
|
source "$BASH_ARGV0" |