From a33c08d03cde85d7b3fe6ccafa5838f0c10d5b30 Mon Sep 17 00:00:00 2001 From: pvincent Date: Sun, 26 Jul 2026 12:56:26 +0400 Subject: [PATCH] failure_type early detection --- poc | 21 +++++++++++++-------- test/stub/scenario.bash | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/poc b/poc index b9f7144..f48eaa0 100755 --- a/poc +++ b/poc @@ -13,14 +13,15 @@ function is_true { } function miaou_debug { - is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "\e[90mDEBUG <==> \e[95m$*\e[0m" || true + is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "\r\e[90mDEBUG <==> \e[95m$*\e[0m" || true } function on_error { code="${1:-100}" - miaou_debug on_error: $$ $BASHPID + miaou_debug "on_error: $code ($$ -- $BASHPID)" if [[ $$ == "$BASHPID" ]]; then >&2 echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: command_error: ${code}" + failure_type="COMMAND_ERROR" exit "$code" else >&2 echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: subshell_error: ${code}" @@ -28,16 +29,20 @@ function on_error { fi } -function on_exit { - code="${1:-0}" - +function dump_stderr { + >&2 printf '' # flush miaou_debug --stderr-- mapfile -t tmp_error <"$MIAOU_BASH_ERROR" for i in "${tmp_error[@]}"; do >&4 echo -e "$i"; done - last_error="${tmp_error[-1]}" miaou_debug --end of stderr-- +} + +function on_exit { + code="${1:-0}" + failure_type="${failure_type:-UNDEFINED}" - miaou_debug "on_exit $code" + dump_stderr + miaou_debug "on_exit $code $failure_type" } function on_pipe { @@ -47,7 +52,7 @@ function on_pipe { mapfile -t tmp_error <"$MIAOU_BASH_ERROR" last_error="${tmp_error[-1]}" regex='.*: line [0-9]+: subshell_error: ([0-9]+)' - [[ $last_error =~ $regex ]] && code=${BASH_REMATCH[1]} + [[ $last_error =~ $regex ]] && code=${BASH_REMATCH[1]} && failure_type="SUBSHELL_ERROR" miaou_debug on_pipe: "${code}" exit "$code" diff --git a/test/stub/scenario.bash b/test/stub/scenario.bash index 01f132b..84d32de 100755 --- a/test/stub/scenario.bash +++ b/test/stub/scenario.bash @@ -16,6 +16,7 @@ function do_subshell_term { echo toto # echo 'toto' | grep none + # echo 'toto' | return 3 echo -n "found1=$(grep nope nope)" echo "found1=$(grep nope nope | grep none)"