almost fix return 0

This commit is contained in:
pvincent
2026-07-24 10:43:42 +04:00
parent 9817730d7f
commit 452bca5e90
3 changed files with 25 additions and 39 deletions
+13 -18
View File
@@ -39,7 +39,6 @@ function on_return {
if [[ "${BASH_COMMAND}" == 'return '* ]]; then
code=$(echo "${BASH_COMMAND}" | cut -d' ' -f2)
if [[ -n "$code" ]] && [[ "$code" -ne 0 ]]; then
trap - DEBUG
>&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: return $code from ${FUNCNAME[1]}"
fi
fi
@@ -49,6 +48,7 @@ function on_exit {
code=${1:-0}
if [[ $code -gt 0 ]]; then
stack_lines=("${BASH_LINENO[@]}")
stack_functions=("${FUNCNAME[@]}")
stack_sources=("${BASH_SOURCE[@]}")
@@ -91,7 +91,7 @@ function on_exit {
failure_payload="${BASH_REMATCH[2]}"
fi
last_error="${BASH_SOURCE[1]}:${BASH_LINENO[0]} subshell term $code"
printf "\r"
printf "\r" # useful!
kill -USR1 $$
else
failure_type='UNKNOWN'
@@ -192,7 +192,7 @@ function on_exit {
}
function miaou_debug {
is_true "${MIAOU_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "*********** DEBUG: $*" || true
}
function ansi_block_continuation {
@@ -204,24 +204,22 @@ function ansi_block_continuation {
}
function ansi_block_error {
BG=RED
FG=BLACK
BG=RED
PADDING=2
local content detail exit_code
content=$(style_ansi "$1")
content=$(style_padding "$content")
detail="$2"
[[ -n "$detail" ]] && detail=$(BG=BLACK FG=WHITE style_padding "$2")
[[ -n "$detail" ]] && detail=$(BG=BLACK FG=WHITE PADDING_LEFT=4 style_padding "$2")
exit_code=$(FG=CYAN style_ansi " $3")
printf "\r"
exit_code=$(FG=CYAN style_ansi "$3")
builtin echo -en "\r"
BLOCK_CONTINUATION_COL=5 style_block "$content$detail$exit_code"
ansi_reset
FG=RED style_ansi " ║"
echo
FG=RED style_ansi " ║" && builtin echo
}
function ansi_traces {
@@ -243,22 +241,19 @@ function ansi_traces {
function dump_failure {
declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
dump_stderr true
miaou_debug "---error box ${failure_type:-} ---"
if [[ ${failure_type} == 'SUBSHELL SOURCE NOT FOUND' ]]; then
:
else
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
miaou_debug '---end of error---'
>&4 ansi_block_error "$failure_type" "$failure_payload" "$code"
fi
miaou_debug '---end of error box---'
miaou_debug '---stacktrace---'
>&4 ansi_traces stack_sources stack_lines stack_functions
miaou_debug '---end of stacktrace---'
cleanup
}