Browse Source

improved miaou_debug on_error

main
pvincent 2 weeks ago
parent
commit
06042ac1f0
  1. 16
      poc
  2. 4
      test/poc.test.bash
  3. 3
      test/stub/scenario.bash

16
poc

@ -105,6 +105,8 @@ function on_error {
failure_code="${1:-200}"
>&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 [[ ! -v failure_type ]]; 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}"
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_lineno=("${BASH_LINENO[@]}")
error_funcname=("${FUNCNAME[@]}")
@ -132,9 +128,15 @@ function on_error {
error_lineno=("${error_lineno[@]}")
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"
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}"
kill -PIPE $$
fi

4
test/poc.test.bash

@ -43,11 +43,13 @@ function fail_type {
set -uo pipefail
assert success
fail_type subshell_term SUBSHELL_ERROR
fail_type unbound_variable UNBOUND_VARIABLE
fail_type unbound_associative UNBOUND_VARIABLE
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 command_not_found COMMAND_NOT_FOUND
# fail_type source_not_found SOURCE_NOT_FOUND

3
test/stub/scenario.bash

@ -28,8 +28,9 @@ function do_subshell_term {
# echo SHOULD NOT SHOW UP!
}
# unable to catch up error when the last command is `!` statement
function do_last_false {
# FIXME: provides error detection
echo 'last false'
! true
}

Loading…
Cancel
Save