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
MIAOU_BASH_ERROR=$(mktemp -t "$(basename "$0").XXXXXXXX" --tmpdir="/run/user/$(id -u)")
MIAOU_BASH_DEBUG=${MIAOU_BASH_DEBUG:-false}
readonly MIAOU_BASH_ERROR MIAOU_BASH_DEBUG
MIAOU_DEBUG=${MIAOU_DEBUG:-false}
readonly MIAOU_BASH_ERROR MIAOU_DEBUG
# FUNCTIONS
@@ -15,7 +15,7 @@ function is_true {
# overridden function which permits backtracing of original `return` statement
function false {
>&2 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} false"
debug "overridden false"
miaou_debug "overridden false"
builtin false
}
@@ -24,7 +24,7 @@ function exit {
code=${1:-0}
# >&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: exit $@"
>&2 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} exit $code"
debug "overridden exit $code"
miaou_debug "overridden exit $code"
builtin exit "$code"
}
@@ -166,7 +166,7 @@ function on_exit {
fi
else
# failure_type='UNDEFINED'
debug "last error=${last_error}"
miaou_debug "last error=${last_error}"
failure_payload="${last_error}"
regex="^ .*:[0-9]* .*\$"
if [[ "$last_error" =~ $regex ]]; then
@@ -196,8 +196,8 @@ function on_exit {
builtin exit "$code"
}
function debug {
is_true "${MIAOU_BASH_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
function miaou_debug {
is_true "${MIAOU_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
}
function ansi_block_continuation {
@@ -248,22 +248,22 @@ function dump_failure {
if [[ ${failure_type} == 'SUBSHELL SOURCE NOT FOUND' ]]; then
:
else
debug '---error---'
miaou_debug '---error---'
if [[ $failure_type == 'SUBSHELL ERROR' ]]; then
>&4 echo -e "${failure_payload}"
else
>&4 ansi_block_error "$failure_type" "$failure_payload" "$code"
fi
debug '---end of error---'
miaou_debug '---end of error---'
fi
debug '---stacktrace---'
miaou_debug '---stacktrace---'
>&4 ansi_traces stack_sources stack_lines stack_functions
# for i in "${failure_traces[@]}"; do
# >&4 echo -e "$i"
# done
debug '---end of stacktrace---'
miaou_debug '---end of stacktrace---'
cleanup
}
@@ -272,13 +272,13 @@ function dump_stderr {
mapfile -t tmp_error <"$MIAOU_BASH_ERROR"
is_true "$last_trim" && unset 'tmp_error[-1]' && tmp_error=("${tmp_error[@]}")
if [[ "${#tmp_error[@]}" -gt 0 ]]; then
debug '---stderr---'
miaou_debug '---stderr---'
>&4 printf '\r'
for i in "${tmp_error[@]}"; do
>&4 echo -e "$i"
done
else
debug '---no stderr---'
miaou_debug '---no stderr---'
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
exec 3> >(tee "$MIAOU_BASH_ERROR" >/dev/null) 4>/dev/stderr
debug '---stdout---'
miaou_debug '---stdout---'
# shellcheck source=/dev/null
source "$BASH_ARGV0" 2>&3
dump_success
+1 -1
View File
@@ -13,8 +13,8 @@ function do_subshell_false {
}
function do_subshell_term {
echo "found1=$(command_not_found)"
echo "found2=$(grep nope nope)"
echo "found1=$(command_not_found)"
echo SHOULD NOT SHOW UP!
}