From cfab4506abd5bcb8afbf6b9c5845cb7ada3279cc Mon Sep 17 00:00:00 2001 From: pvincent Date: Sat, 25 Jul 2026 11:32:45 +0400 Subject: [PATCH] not yet done with subshell error --- bin/miaou-bash | 10 +++++----- test/miaou-bash.test.bash | 3 +++ test/stub/scenario.bash | 12 ++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/bin/miaou-bash b/bin/miaou-bash index 7918878..a982c6e 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -161,10 +161,9 @@ function on_exit { fi fi else - failure_type='UNDEFINED' - miaou_debug "last error=${last_error}" failure_payload="${last_error}" - regex="^ .*:[0-9]* .*\$" + miaou_debug "UNDEFINED last error=${last_error}" + regex="╟─⟶" if [[ "$last_error" =~ $regex ]]; then if [[ "${code}" == 128 ]]; then failure_type='SUBSHELL_SOURCE_NOT_FOUND' @@ -174,6 +173,7 @@ function on_exit { stack_functions[0]="${stack_functions[0]} (hint: prefer source than subshell:3)" fi else + failure_type='UNDEFINED' regex='^subshell term:' if [[ "$last_error" =~ $regex ]]; then failure_type='SUBSHELL_TERM2' @@ -229,7 +229,7 @@ function ansi_traces { declare -n functions=$3 optional=false for i in "${!sources[@]}"; do - FG=RED style_ansi " ╟─⟶" + FG=RED style_ansi " ╟─⟶ " location=$(printf "%40s" "${sources[$i]}:${lines[$i]}") is_true "$optional" && location=$(FG=GRAY STYLE=ITALIC style_ansi "$location") || @@ -297,7 +297,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 -miaou_debug '---stdout---' +miaou_debug "---stdout--$$ $BASHPID $PPID--" # shellcheck source=/dev/null source "$BASH_ARGV0" 2>&3 dump_success diff --git a/test/miaou-bash.test.bash b/test/miaou-bash.test.bash index 40e564c..2f4c97e 100755 --- a/test/miaou-bash.test.bash +++ b/test/miaou-bash.test.bash @@ -55,8 +55,11 @@ fail_type command_not_found COMMAND_NOT_FOUND fail_type exit EXIT fail_type source_not_found SOURCE_NOT_FOUND fail_type file_not_found FILE_NOT_FOUND +fail_type subshell_source_not_found SUBSHELL_SOURCE_NOT_FOUND +fail_type subshell_error SUBSHELL_ERROR failed=$((TEST_COUNT - SUCCESS_COUNT)) + if [[ $failed -gt 0 ]]; then ratio=$((100 * SUCCESS_COUNT / TEST_COUNT)) echo "${ratio}% passed, $SUCCESS_COUNT succeeded, $failed failed!" diff --git a/test/stub/scenario.bash b/test/stub/scenario.bash index 733e8a8..2d043d3 100755 --- a/test/stub/scenario.bash +++ b/test/stub/scenario.bash @@ -86,6 +86,18 @@ function do_source_not_found { function do_file_not_found { ./lib/fake/nope.bash } + +function do_subshell_source_not_found { + output=$(miaou_debug "---subshell1--$$ $BASHPID $PPID--") + output=$(miaou_debug "---subshell2--$$ $BASHPID $PPID--") + : "$output" + "${MIAOU_BASH_DIR}/test/stub/extra/library.bash" + +} + +function do_subshell_error { + : +} # FUNCTIONS function call_function_which_will_exit {