improved miaou_debug on_error
This commit is contained in:
@@ -105,6 +105,8 @@ function on_error {
|
|||||||
failure_code="${1:-200}"
|
failure_code="${1:-200}"
|
||||||
>&4 printf '\r' # TODO: force carriage return explicitly, is it really useful?
|
>&4 printf '\r' # TODO: force carriage return explicitly, is it really useful?
|
||||||
|
|
||||||
|
miaou_debug "<on_error code=${failure_code} command=[${BASH_COMMAND}]>"
|
||||||
|
|
||||||
if [[ $$ == "$BASHPID" ]]; then
|
if [[ $$ == "$BASHPID" ]]; then
|
||||||
if [[ ! -v failure_type ]]; then
|
if [[ ! -v failure_type ]]; then
|
||||||
if [[ ${BASH_COMMAND} == 'false' ]]; then
|
if [[ ${BASH_COMMAND} == 'false' ]]; then
|
||||||
@@ -116,12 +118,6 @@ function on_error {
|
|||||||
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}"
|
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -v failure_payload ]]; then
|
|
||||||
miaou_debug "<on_error exit=$failure_code type=${failure_type} payload=${failure_payload} />"
|
|
||||||
else
|
|
||||||
miaou_debug "<on_error exit=$failure_code type=${failure_type} />"
|
|
||||||
fi
|
|
||||||
|
|
||||||
error_source=("${BASH_SOURCE[@]}")
|
error_source=("${BASH_SOURCE[@]}")
|
||||||
error_lineno=("${BASH_LINENO[@]}")
|
error_lineno=("${BASH_LINENO[@]}")
|
||||||
error_funcname=("${FUNCNAME[@]}")
|
error_funcname=("${FUNCNAME[@]}")
|
||||||
@@ -132,9 +128,15 @@ function on_error {
|
|||||||
error_lineno=("${error_lineno[@]}")
|
error_lineno=("${error_lineno[@]}")
|
||||||
error_funcname=("${error_funcname[@]}")
|
error_funcname=("${error_funcname[@]}")
|
||||||
|
|
||||||
|
if [[ -v failure_payload ]]; then
|
||||||
|
miaou_debug "</on_error exit=$failure_code type=${failure_type} payload=${failure_payload}>"
|
||||||
|
else
|
||||||
|
miaou_debug "</on_error exit=$failure_code type=${failure_type}>"
|
||||||
|
fi
|
||||||
|
|
||||||
builtin exit "$failure_code"
|
builtin exit "$failure_code"
|
||||||
else
|
else
|
||||||
miaou_debug "<on_error pipe=$failure_code sub_pid=$BASHPID pid=$$ command='${BASH_COMMAND}'/>"
|
miaou_debug "</on_error pipe=$failure_code sub_pid=$BASHPID pid=$$ command='${BASH_COMMAND}'>"
|
||||||
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" 'SUBSHELL_ERROR' "${BASH_COMMAND}"
|
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" 'SUBSHELL_ERROR' "${BASH_COMMAND}"
|
||||||
kill -PIPE $$
|
kill -PIPE $$
|
||||||
fi
|
fi
|
||||||
|
|||||||
+3
-1
@@ -43,11 +43,13 @@ function fail_type {
|
|||||||
set -uo pipefail
|
set -uo pipefail
|
||||||
|
|
||||||
assert success
|
assert success
|
||||||
|
|
||||||
fail_type subshell_term SUBSHELL_ERROR
|
fail_type subshell_term SUBSHELL_ERROR
|
||||||
fail_type unbound_variable UNBOUND_VARIABLE
|
fail_type unbound_variable UNBOUND_VARIABLE
|
||||||
fail_type unbound_associative UNBOUND_VARIABLE
|
fail_type unbound_associative UNBOUND_VARIABLE
|
||||||
fail_type false FALSE
|
fail_type false FALSE
|
||||||
fail_type return RETURN
|
fail_type last_false COMMAND_ERROR
|
||||||
|
fail_type subshell_term SUBSHELL_ERROR
|
||||||
fail_type exit EXIT
|
fail_type exit EXIT
|
||||||
fail_type command_not_found COMMAND_NOT_FOUND
|
fail_type command_not_found COMMAND_NOT_FOUND
|
||||||
# fail_type source_not_found SOURCE_NOT_FOUND
|
# fail_type source_not_found SOURCE_NOT_FOUND
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ function do_subshell_term {
|
|||||||
# echo SHOULD NOT SHOW UP!
|
# echo SHOULD NOT SHOW UP!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# unable to catch up error when the last command is `!` statement
|
||||||
function do_last_false {
|
function do_last_false {
|
||||||
# FIXME: provides error detection
|
echo 'last false'
|
||||||
! true
|
! true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user