exit caught up
This commit is contained in:
@@ -49,6 +49,25 @@ function is_true {
|
|||||||
function miaou_debug {
|
function miaou_debug {
|
||||||
is_true "${MIAOU_DEBUG}" && >&4 builtin echo -e "\e[90m <== DEBUG ==> \e[33m$*\e[0m" || true
|
is_true "${MIAOU_DEBUG}" && >&4 builtin echo -e "\e[90m <== DEBUG ==> \e[33m$*\e[0m" || true
|
||||||
}
|
}
|
||||||
|
# overridden function which permits backtracing of the original `exit` statement
|
||||||
|
function exit {
|
||||||
|
failure_code=${1:-0}
|
||||||
|
failure_type="EXIT"
|
||||||
|
miaou_debug "<exit code=$failure_code overridden/>"
|
||||||
|
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}"
|
||||||
|
|
||||||
|
error_source=("${BASH_SOURCE[@]}")
|
||||||
|
error_lineno=("${BASH_LINENO[@]}")
|
||||||
|
error_funcname=("${FUNCNAME[@]}")
|
||||||
|
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]'
|
||||||
|
unset 'error_source[0]' 'error_lineno[-1]' 'error_funcname[0]'
|
||||||
|
error_funcname[-1]='<main>'
|
||||||
|
error_source=("${error_source[@]}")
|
||||||
|
error_lineno=("${error_lineno[@]}")
|
||||||
|
error_funcname=("${error_funcname[@]}")
|
||||||
|
|
||||||
|
builtin exit "$failure_code"
|
||||||
|
}
|
||||||
|
|
||||||
function tty_ansi {
|
function tty_ansi {
|
||||||
local code
|
local code
|
||||||
@@ -70,7 +89,7 @@ function print_miaou_error {
|
|||||||
|
|
||||||
function on_error {
|
function on_error {
|
||||||
failure_code="${1:-200}"
|
failure_code="${1:-200}"
|
||||||
>&4 printf '\r' # force carriage return explicitly
|
>&4 printf '\r' # TODO: force carriage return explicitly, is it really useful?
|
||||||
|
|
||||||
if [[ $$ == "$BASHPID" ]]; then
|
if [[ $$ == "$BASHPID" ]]; then
|
||||||
miaou_debug "<on_error exit=$failure_code/>"
|
miaou_debug "<on_error exit=$failure_code/>"
|
||||||
@@ -87,7 +106,7 @@ function on_error {
|
|||||||
error_lineno=("${error_lineno[@]}")
|
error_lineno=("${error_lineno[@]}")
|
||||||
error_funcname=("${error_funcname[@]}")
|
error_funcname=("${error_funcname[@]}")
|
||||||
|
|
||||||
exit "$failure_code"
|
builtin exit "$failure_code"
|
||||||
else
|
else
|
||||||
miaou_debug "<on_error pipe=$failure_code sub_pid=$BASHPID pid=$$/>"
|
miaou_debug "<on_error pipe=$failure_code sub_pid=$BASHPID pid=$$/>"
|
||||||
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" 'SUBSHELL_ERROR'
|
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" 'SUBSHELL_ERROR'
|
||||||
@@ -122,7 +141,7 @@ function on_pipe {
|
|||||||
failure_type="PIPE_ERROR"
|
failure_type="PIPE_ERROR"
|
||||||
fi
|
fi
|
||||||
miaou_debug "<on_pipe exit=$failure_code sub_pid=$BASHPID pid=$$/>"
|
miaou_debug "<on_pipe exit=$failure_code sub_pid=$BASHPID pid=$$/>"
|
||||||
exit "$failure_code"
|
builtin exit "$failure_code"
|
||||||
}
|
}
|
||||||
|
|
||||||
function dump_stderr {
|
function dump_stderr {
|
||||||
@@ -234,7 +253,7 @@ trap 'on_error $?' ERR
|
|||||||
trap 'on_exit $?' EXIT
|
trap 'on_exit $?' EXIT
|
||||||
trap 'on_pipe' PIPE
|
trap 'on_pipe' PIPE
|
||||||
|
|
||||||
if [[ -e /proc/$$/fd/3 ]]; then exec 4>&3 3>&-; else exec 4>/dev/tty; fi
|
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"
|
exec 3>/dev/stderr 2>"$MIAOU_BASH_ERROR"
|
||||||
|
|
||||||
miaou_debug "<source from=$BASH_ARGV0 pid=${BASHPID}>"
|
miaou_debug "<source from=$BASH_ARGV0 pid=${BASHPID}>"
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ function do_command_error {
|
|||||||
|
|
||||||
function call_function_which_will_exit {
|
function call_function_which_will_exit {
|
||||||
exit 99
|
exit 99
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function F2 {
|
function F2 {
|
||||||
|
|||||||
Reference in New Issue
Block a user