100% tests passed

This commit is contained in:
pvincent
2026-08-27 10:40:46 +04:00
parent 639b7d967e
commit 0cb5f5501d
5 changed files with 83 additions and 43 deletions
+31 -21
View File
@@ -153,31 +153,39 @@ function on_error {
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}" "${failure_payload}"
load_tmp_error # cannot print_miaou_error after investigation
miaou_debug "<investigate_tmp_error pid=${BASHPID}>"
miaou_debug "<investigate_tmp_error_pass1 pid=${BASHPID}>"
if [[ ${#tmp_error[@]} -gt 1 ]]; then
local last_error regex
last_error="${tmp_error[-2]}" # the second latest cause previous print_miaou_error above
miaou_debug "<analyze last_error={${last_error}} locale=$MIAOU_LOCALE>"
regex='^(.*): line ([0-9]+): (.*): command not found$'
if [[ "$MIAOU_LOCALE" == 'fr' ]]; then
NBSP=$'\xc2\xa0'
last_error="${last_error//$NBSP/ }"
miaou_debug "<strip_nbsp locale=$MIAOU_LOCALE/>" # FIXME: raise issue 'commande introuvable NBSP' within fr.po!
fi
regex="$MSG_COMMAND_NOT_FOUND_REGEX"
if [[ $failure_code == 127 && "$last_error" =~ $regex ]]; then
failure_type='COMMAND_NOT_FOUND'
failure_payload="${BASH_REMATCH[3]}"
miaou_debug "<command_not_found payload=${failure_payload}/>"
else
regex='^(.*): line ([0-9]+): (.*): No such file or directory$'
regex="$MSG_FILE_NOT_FOUND_REGEX"
if [[ $failure_code == 127 && "$last_error" =~ $regex ]]; then
failure_type='FILE_NOT_FOUND'
failure_payload="${BASH_REMATCH[3]}"
miaou_debug "<file_not_found payload=${failure_payload}/>"
elif ! is_true "$CHILD_PROCESS"; then
miaou_debug "<miaou_trace only=main>"
# in main process only, not from children!
local regex2 source lineno funcname
last_error="${tmp_error[-1]}"
regex2='^[[:space:]]+miaou_trace: source=(.*) lineno=(.*) funcname=(.*)$'
if [[ "$last_error" =~ $regex2 ]]; then
miaou_debug "<miaou_trace>"
source="${BASH_REMATCH[1]}"
lineno="${BASH_REMATCH[2]}"
funcname="${BASH_REMATCH[3]}"
@@ -213,14 +221,14 @@ function on_error {
fi
break
fi
# miaou_debug '</index>'
done
miaou_debug "</miaou_trace/>"
fi
miaou_debug "</miaou_trace/>"
fi
fi
miaou_debug "</analyze>"
fi
miaou_debug '</investigate_tmp_error>'
miaou_debug '</investigate_tmp_error_pass1>'
fi
fi
@@ -371,7 +379,7 @@ function dump_failure {
}
function save_err_trace_to_main {
miaou_debug "<save_stacktrace_to_stderr count=${#error_source[@]} to=${MIAOU_BASH_ERROR_CHILDREN}>"
miaou_debug "<save_backtrace_to_stderr count=${#error_source[@]} to=${MIAOU_BASH_ERROR_CHILDREN}>"
local i source lineno funcname
for i in "${tmp_error[@]}"; do >>"$MIAOU_BASH_ERROR_CHILDREN" echo "$i"; done
for i in "${!error_source[@]}"; do
@@ -381,15 +389,15 @@ function save_err_trace_to_main {
# miaou_debug "<trace source=${source} lineno=${lineno} funcname=${funcname}/>"
>>"$MIAOU_BASH_ERROR_CHILDREN" echo -e "\tmiaou_trace: source=${source} lineno=${lineno} funcname=${funcname}"
done
miaou_debug "</save_stacktrace_to_stderr>"
miaou_debug "</save_backtrace_to_stderr>"
}
function dump_stacktrace {
miaou_debug "<stacktrace count=${#error_source[@]}>"
function dump_backtrace {
miaou_debug "<backtrace count=${#error_source[@]}>"
local i source lineno funcname
for i in "${!error_source[@]}"; do
tty_ansi FG_MAGENTA
echo -n " ╟──▷"
echo -n " ╟──▷ "
tty_ansi STYLE_ITALIC
source="${error_source[$i]}"
lineno="${error_lineno[$i]}"
@@ -404,7 +412,8 @@ function dump_stacktrace {
[[ $i -gt 0 ]] && tty_ansi FG_GRAY
fi
printf "%40s:%.4s" "$source" "$lineno"
local min_length=45 # TODO: compute from previous backtrace (children) and get the max
printf "%${min_length}s:%.4s" "$source" "$lineno"
tty_ansi RESET
printf " \t%s" "$funcname"
@@ -417,7 +426,7 @@ function dump_stacktrace {
echo
done
miaou_debug '</stacktrace>'
miaou_debug '</backtrace>'
}
function load_tmp_error {
@@ -517,9 +526,8 @@ function on_exit {
elif [[ ! -v failure_type ]]; then
if [[ ${#tmp_error[@]} -gt 0 ]]; then
last_error="${tmp_error[-1]}"
miaou_debug "<investigate_tmp_error last={$last_error}>"
regex='^(.*): line ([0-9]+): (.*): unbound variable$'
miaou_debug "<investigate_tmp_error_pass2 last={$last_error}>"
regex="$MSG_UNBOUND_VARIABLE_REGEX"
if [[ $failure_code -eq 1 ]] && [[ "$last_error" =~ $regex ]]; then
failure_type='UNBOUND_VARIABLE'
failure_payload="${BASH_REMATCH[3]}"
@@ -535,7 +543,7 @@ function on_exit {
add_miaou_error "$source" "$line" "${failure_code}" "${failure_type}" "${failure_payload}"
miaou_debug "<unbound_variable source=${source} line=${line} payload=${failure_payload}/>"
else
regex='^(.*): line ([0-9]+): (.*): No such file or directory$'
regex="$MSG_SOURCE_NOT_FOUND_REGEX"
if [[ $failure_code -eq 1 ]] && [[ "$last_error" =~ $regex ]]; then
failure_type='SOURCE_NOT_FOUND'
failure_payload="${BASH_REMATCH[3]}"
@@ -555,7 +563,7 @@ function on_exit {
failure_payload="$BASH_COMMAND"
fi
fi
miaou_debug "</investigate_tmp_error>"
miaou_debug "</investigate_tmp_error_pass2>"
fi
fi
fi
@@ -568,7 +576,7 @@ function on_exit {
else
2>&3 >&4 dump_failure
if [[ -v error_source ]]; then
2>&3 >&4 dump_stacktrace
2>&3 >&4 dump_backtrace
fi
fi
fi
@@ -688,6 +696,7 @@ if [[ -v SCRIPT ]]; then
miaou_debug "<script found=$SCRIPT args_count=$#/>"
[[ $# -gt 0 ]] && shift
fi
if is_true "$CHILD_PROCESS"; then
# any nested children
exec 4>/dev/tty 2>"$MIAOU_BASH_ERROR"
@@ -702,10 +711,11 @@ else
exec 4>/dev/tty
fi
exec 3>&2 2>"$MIAOU_BASH_ERROR"
load_locale
miaou_debug "<main file=$BASH_ARGV0 pid=${BASHPID}/>"
fi
load_locale
# shellcheck source=/dev/null
if [[ "$HEREDOC" == true ]]; then
miaou_debug '<source heredoc/>'