This commit is contained in:
pvincent
2026-07-27 00:10:47 +04:00
parent 397a57a27e
commit f2cd414660
2 changed files with 33 additions and 12 deletions
+26 -7
View File
@@ -16,12 +16,15 @@ function is_true {
# example: # example:
# alias toto="bash -c \"[[ \\\$MIAOU_DEBUG == 'true' ]] && echo yes \\\$* || echo nope\"" # alias toto="bash -c \"[[ \\\$MIAOU_DEBUG == 'true' ]] && echo yes \\\$* || echo nope\""
function miaou_debug { function miaou_debug {
is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "\r\e[90mDEBUG <==> \e[95m$*\e[0m" || true is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "\e[90mDEBUG <==> \e[33m$*\e[0m" || true
} }
function on_error { function on_error {
>/dev/tty printf '\r' # force carriage return explicitly
code="${1:-100}" code="${1:-100}"
miaou_debug "on_error: $code ($$ -- $BASHPID)" miaou_debug "on_error: $code ($$ -- $BASHPID)"
if [[ $$ == "$BASHPID" ]]; then if [[ $$ == "$BASHPID" ]]; then
>&2 echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: command_error: ${code}" >&2 echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: command_error: ${code}"
failure_type="COMMAND_ERROR" failure_type="COMMAND_ERROR"
@@ -33,19 +36,34 @@ function on_error {
} }
function dump_stderr { function dump_stderr {
>&2 printf '' # force flush
miaou_debug --stderr-- miaou_debug --stderr--
mapfile -t tmp_error <"$MIAOU_BASH_ERROR" mapfile -t tmp_error <"$MIAOU_BASH_ERROR"
for i in "${tmp_error[@]}"; do >&4 echo -e "$i"; done for i in "${tmp_error[@]}"; do
echo -e "$i"
done
miaou_debug --end of stderr-- miaou_debug --end of stderr--
} }
function dump_failure {
miaou_debug --error box--
echo FAILURE: "$failure_type"
miaou_debug --end of error box--
}
function dump_stacktrace {
miaou_debug --stacktrace--
echo stacktrace...
miaou_debug --end of stacktrace--
}
function on_exit { function on_exit {
code="${1:-0}" code="${1:-0}"
failure_type="${failure_type:-UNDEFINED}" failure_type="${failure_type:-UNDEFINED}"
dump_stderr 2>&3 >&3 dump_stderr
2>&3 >&3 dump_failure
2>&3 >&3 dump_stacktrace
miaou_debug "on_exit $code $failure_type" miaou_debug "on_exit $code $failure_type"
} }
@@ -73,6 +91,7 @@ trap 'on_exit $?' EXIT
trap 'on_pipe' PIPE trap 'on_pipe' PIPE
echo "--SOURCE scenario ${BASHPID}" echo "--SOURCE scenario ${BASHPID}"
exec 3> >(tee "$MIAOU_BASH_ERROR" >/dev/null) 4>/dev/stderr exec 3>/dev/stderr
source ./test/stub/scenario.bash subshell_term 2>&3 2>"$MIAOU_BASH_ERROR" source ./test/stub/scenario.bash subshell_term
exec 3>-
echo "--SUCCESS scenario" echo "--SUCCESS scenario"
+7 -5
View File
@@ -14,15 +14,17 @@ function do_subshell_false {
function do_subshell_term { function do_subshell_term {
echo -n toto est fluo echo first line.
>&2 echo -n 'error in transla...' # echo -n second line...
# >&2 echo stderr1
# grep none none 2>/dev/null
# echo 'toto' | grep none # echo 'toto' | grep none
# echo 'toto' | return 3 # echo 'toto' | return 3
echo -n "found1=$(grep nope nope)" echo -n "found1=$(grep nope nope)"
echo "found1=$(grep nope nope | grep none)" # echo "found1=$(grep nope nope | grep none)"
echo "found2=$(command_not_found)" # echo "found2=$(command_not_found)"
echo SHOULD NOT SHOW UP! # echo SHOULD NOT SHOW UP!
} }
function do_last_false { function do_last_false {