From 91ba36f1436ae27ba6c00cac79083402bca67d98 Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 30 Jul 2026 12:31:01 +0400 Subject: [PATCH] clean child stderr; need sort out --- bin/miaou-bash | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/bin/miaou-bash b/bin/miaou-bash index e40978b..40ba50d 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -290,7 +290,6 @@ function dump_failure { function save_err_trace_to_main { 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 source="${error_source[$i]}" lineno="${error_lineno[$i]}" @@ -298,6 +297,7 @@ function save_err_trace_to_main { miaou_debug "" >>"$MIAOU_BASH_ERROR_CHILDREN" echo -e "\tmiaou_trace: source=${source} lineno=${lineno} funcname=${funcname}" done + for i in "${tmp_error[@]}"; do >>"$MIAOU_BASH_ERROR_CHILDREN" echo "$i"; done miaou_debug "" } @@ -323,7 +323,25 @@ function dump_stacktrace { function load_tmp_error { miaou_debug "" if [[ ! -v tmp_error ]]; then + local count count_children tmp_error_children + if [[ -f "$MIAOU_BASH_ERROR_CURRENT_CHILDREN" ]]; then + miaou_debug "" + mapfile -t tmp_error_children <"$MIAOU_BASH_ERROR_CURRENT_CHILDREN" + local count_children=${#tmp_error_children[@]} + if [[ $count_children == 0 ]]; then + miaou_debug "" + else + miaou_debug "" + fi + miaou_debug "" + rm "$MIAOU_BASH_ERROR_CURRENT_CHILDREN" + fi + mapfile -t tmp_error <"$MIAOU_BASH_ERROR" + + if [[ -v count_children && $count_children -gt 0 ]]; then + tmp_error=("${tmp_error[@]}" "${tmp_error_children[@]}") + fi local count=${#tmp_error[@]} if [[ $count == 0 ]]; then miaou_debug "" @@ -448,21 +466,18 @@ function build_miaou_bash_error { [[ -f "${directory}/${PPID}.tmp" ]] && CHILD_PROCESS=true mkdir -p "$directory" - if is_true $CHILD_PROCESS; then - MIAOU_BASH_ERROR_CHILDREN="${directory}/${PPID}.children.tmp" - fi + MIAOU_BASH_ERROR_CURRENT_CHILDREN="${directory}/$$.children.tmp" + MIAOU_BASH_ERROR_CHILDREN="${directory}/${PPID}.children.tmp" MIAOU_BASH_ERROR="${directory}/$$.tmp" rm -f "$MIAOU_BASH_ERROR" - readonly MIAOU_BASH_ERROR_CHILDREN MIAOU_BASH_ERROR CHILD_PROCESS + readonly MIAOU_BASH_ERROR_CURRENT_CHILDREN MIAOU_BASH_ERROR_CHILDREN MIAOU_BASH_ERROR CHILD_PROCESS } function cleanup { - if ! is_true $CHILD_PROCESS; then - miaou_debug '' - trap - ERR EXIT PIPE RETURN - # rm "$MIAOU_BASH_ERROR" - fi + miaou_debug '' + trap - ERR EXIT PIPE RETURN + rm -f "$MIAOU_BASH_ERROR" } ## main