smarter ansi_error

This commit is contained in:
pvincent
2026-07-21 11:33:25 +04:00
parent ef95f5cce8
commit 0a5e0cdce4
4 changed files with 105 additions and 39 deletions
+50 -7
View File
@@ -188,7 +188,6 @@ function on_exit {
failure_traces+=("$stack_detail")
done
dump_failure
# builtin exit "$code"
else
dump_success
fi
@@ -199,6 +198,46 @@ function debug {
is_true "${MIAOU_BASH_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
}
function ansi_block_continuation {
tput sc
tput cuu 1
BG=RED FG=BLACK style_ansi "\t╦"
tput rc
FG=RED style_ansi "\t║\n"
}
function ansi_block_error {
BG=RED
FG=BLACK
PADDING=2
local content detail exit_code
content=$(style_ansi "$1")
content=$(style_padding "$content")
detail=$(BG=BLACK style_padding "$2")
exit_code=$(FG=CYAN style_ansi " $3")
style_block "$content$detail$exit_code"
ansi_reset
}
function ansi_traces {
local optional location sources lines functions
declare -n sources=$1
declare -n lines=$2
declare -n functions=$3
optional=false
for i in "${!sources[@]}"; do
FG=RED style_ansi "\t╟─⟶"
location="${sources[$i]}:${lines[$i]}"
is_true "$optional" &&
location=$(FG=GRAY STYLE=ITALIC style_ansi "\t$location") || # FIXME: \t should not be required!
location=$(STYLE=ITALIC style_ansi "$location")
printf "%40s\t%s\n" "${location}" "${functions[$i]}"
optional=true
done
}
function dump_failure {
dump_stderr true
debug '---stacktrace---'
@@ -208,14 +247,18 @@ function dump_failure {
if [[ $failure_type == 'SUBSHELL ERROR' ]]; then
>&4 echo -e "${failure_payload}"
else
>&4 echo -e "\tCODE: ${code}"
>&4 echo -e "\tTYPE: ${failure_type}"
>&4 echo -e "\tPAYLOAD: ${failure_payload}"
declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
>&4 ansi_block_error "$failure_type" "$failure_payload" "$code"
>&4 ansi_block_continuation
fi
fi
for i in "${failure_traces[@]}"; do
>&4 echo -e "$i"
done
declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
>&4 ansi_traces stack_sources stack_lines stack_functions
# for i in "${failure_traces[@]}"; do
# >&4 echo -e "$i"
# done
debug '---end of stacktrace---'
cleanup
}