From 0cb5f5501d3b0928b6a0d5ebccf64b9a3c356fdf Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 27 Aug 2026 10:40:46 +0400 Subject: [PATCH] 100% tests passed --- bin/miaou-bash | 52 +++++++++++++++++++++++---------------- locales/en.sh | 3 +++ locales/es.sh | 6 +++-- locales/fr.sh | 10 +++++++- test/miaou-bash.test.bash | 51 +++++++++++++++++++++++++------------- 5 files changed, 81 insertions(+), 41 deletions(-) diff --git a/bin/miaou-bash b/bin/miaou-bash index c5fc94c..82b6e40 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -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 "" + miaou_debug "" 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 "" + + if [[ "$MIAOU_LOCALE" == 'fr' ]]; then + NBSP=$'\xc2\xa0' + last_error="${last_error//$NBSP/ }" + miaou_debug "" # FIXME: raise issue 'commande introuvable NBSP' within fr.po! + fi - regex='^(.*): line ([0-9]+): (.*): command not found$' + 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 "" 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 "" elif ! is_true "$CHILD_PROCESS"; then + miaou_debug "" # 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 "" source="${BASH_REMATCH[1]}" lineno="${BASH_REMATCH[2]}" funcname="${BASH_REMATCH[3]}" @@ -213,14 +221,14 @@ function on_error { fi break fi - # miaou_debug '' done - miaou_debug "" fi + miaou_debug "" fi fi + miaou_debug "" fi - miaou_debug '' + miaou_debug '' fi fi @@ -371,7 +379,7 @@ function dump_failure { } function save_err_trace_to_main { - miaou_debug "" + miaou_debug "" 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 "" >>"$MIAOU_BASH_ERROR_CHILDREN" echo -e "\tmiaou_trace: source=${source} lineno=${lineno} funcname=${funcname}" done - miaou_debug "" + miaou_debug "" } -function dump_stacktrace { - miaou_debug "" +function dump_backtrace { + miaou_debug "" 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 '' + miaou_debug '' } 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 "" - - regex='^(.*): line ([0-9]+): (.*): unbound variable$' + miaou_debug "" + 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 "" 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 "" + miaou_debug "" 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 "