MIAOU_DEBUG

This commit is contained in:
pvincent
2026-07-23 10:27:13 +04:00
parent 56bc5d5a72
commit 59826c3997
2 changed files with 15 additions and 15 deletions
+14 -14
View File
@@ -3,8 +3,8 @@
# CONSTANTS # CONSTANTS
MIAOU_BASH_ERROR=$(mktemp -t "$(basename "$0").XXXXXXXX" --tmpdir="/run/user/$(id -u)") MIAOU_BASH_ERROR=$(mktemp -t "$(basename "$0").XXXXXXXX" --tmpdir="/run/user/$(id -u)")
MIAOU_BASH_DEBUG=${MIAOU_BASH_DEBUG:-false} MIAOU_DEBUG=${MIAOU_DEBUG:-false}
readonly MIAOU_BASH_ERROR MIAOU_BASH_DEBUG readonly MIAOU_BASH_ERROR MIAOU_DEBUG
# FUNCTIONS # FUNCTIONS
@@ -15,7 +15,7 @@ function is_true {
# overridden function which permits backtracing of original `return` statement # overridden function which permits backtracing of original `return` statement
function false { function false {
>&2 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} false" >&2 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} false"
debug "overridden false" miaou_debug "overridden false"
builtin false builtin false
} }
@@ -24,7 +24,7 @@ function exit {
code=${1:-0} code=${1:-0}
# >&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: exit $@" # >&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: exit $@"
>&2 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} exit $code" >&2 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} exit $code"
debug "overridden exit $code" miaou_debug "overridden exit $code"
builtin exit "$code" builtin exit "$code"
} }
@@ -166,7 +166,7 @@ function on_exit {
fi fi
else else
# failure_type='UNDEFINED' # failure_type='UNDEFINED'
debug "last error=${last_error}" miaou_debug "last error=${last_error}"
failure_payload="${last_error}" failure_payload="${last_error}"
regex="^ .*:[0-9]* .*\$" regex="^ .*:[0-9]* .*\$"
if [[ "$last_error" =~ $regex ]]; then if [[ "$last_error" =~ $regex ]]; then
@@ -196,8 +196,8 @@ function on_exit {
builtin exit "$code" builtin exit "$code"
} }
function debug { function miaou_debug {
is_true "${MIAOU_BASH_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true is_true "${MIAOU_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
} }
function ansi_block_continuation { function ansi_block_continuation {
@@ -248,22 +248,22 @@ function dump_failure {
if [[ ${failure_type} == 'SUBSHELL SOURCE NOT FOUND' ]]; then if [[ ${failure_type} == 'SUBSHELL SOURCE NOT FOUND' ]]; then
: :
else else
debug '---error---' miaou_debug '---error---'
if [[ $failure_type == 'SUBSHELL ERROR' ]]; then if [[ $failure_type == 'SUBSHELL ERROR' ]]; then
>&4 echo -e "${failure_payload}" >&4 echo -e "${failure_payload}"
else else
>&4 ansi_block_error "$failure_type" "$failure_payload" "$code" >&4 ansi_block_error "$failure_type" "$failure_payload" "$code"
fi fi
debug '---end of error---' miaou_debug '---end of error---'
fi fi
debug '---stacktrace---' miaou_debug '---stacktrace---'
>&4 ansi_traces stack_sources stack_lines stack_functions >&4 ansi_traces stack_sources stack_lines stack_functions
# for i in "${failure_traces[@]}"; do # for i in "${failure_traces[@]}"; do
# >&4 echo -e "$i" # >&4 echo -e "$i"
# done # done
debug '---end of stacktrace---' miaou_debug '---end of stacktrace---'
cleanup cleanup
} }
@@ -272,13 +272,13 @@ function dump_stderr {
mapfile -t tmp_error <"$MIAOU_BASH_ERROR" mapfile -t tmp_error <"$MIAOU_BASH_ERROR"
is_true "$last_trim" && unset 'tmp_error[-1]' && tmp_error=("${tmp_error[@]}") is_true "$last_trim" && unset 'tmp_error[-1]' && tmp_error=("${tmp_error[@]}")
if [[ "${#tmp_error[@]}" -gt 0 ]]; then if [[ "${#tmp_error[@]}" -gt 0 ]]; then
debug '---stderr---' miaou_debug '---stderr---'
>&4 printf '\r' >&4 printf '\r'
for i in "${tmp_error[@]}"; do for i in "${tmp_error[@]}"; do
>&4 echo -e "$i" >&4 echo -e "$i"
done done
else else
debug '---no stderr---' miaou_debug '---no stderr---'
fi fi
} }
@@ -306,7 +306,7 @@ BASH_ARGV0="$1" && shift # to pretend script runs by itself
# magic FD + delayed tee => /dev/fd/3 means delayed stderr, /dev/fd/4 remains original stderr # magic FD + delayed tee => /dev/fd/3 means delayed stderr, /dev/fd/4 remains original stderr
exec 3> >(tee "$MIAOU_BASH_ERROR" >/dev/null) 4>/dev/stderr exec 3> >(tee "$MIAOU_BASH_ERROR" >/dev/null) 4>/dev/stderr
debug '---stdout---' miaou_debug '---stdout---'
# shellcheck source=/dev/null # shellcheck source=/dev/null
source "$BASH_ARGV0" 2>&3 source "$BASH_ARGV0" 2>&3
dump_success dump_success
+1 -1
View File
@@ -13,8 +13,8 @@ function do_subshell_false {
} }
function do_subshell_term { function do_subshell_term {
echo "found1=$(command_not_found)"
echo "found2=$(grep nope nope)" echo "found2=$(grep nope nope)"
echo "found1=$(command_not_found)"
echo SHOULD NOT SHOW UP! echo SHOULD NOT SHOW UP!
} }