not yet children

This commit is contained in:
pvincent
2026-07-30 11:10:28 +04:00
parent 10ae8fef2d
commit b989cc012c
3 changed files with 49 additions and 30 deletions
+40 -12
View File
@@ -287,6 +287,20 @@ function dump_failure {
miaou_debug '</error_box>'
}
function save_err_trace_to_main {
miaou_debug "<save_stacktrace_to_stderr count=${#error_source[@]} to=${MIAOU_BASH_ERROR_CHILDREN}>"
local i source lineno funcname
for i in "${!error_source[@]}"; do
source="${error_source[$i]}"
lineno="${error_lineno[$i]}"
funcname="${error_funcname[$i]}"
miaou_debug "<trace source=${source} lineno=${lineno} funcname=${funcname}/>"
>>"$MIAOU_BASH_ERROR_CHILDREN" echo "miaou_trace: source=${source} lineno=${lineno} funcname=${funcname}"
done
for i in "${tmp_error[@]}"; do >>"$MIAOU_BASH_ERROR_CHILDREN" echo "$i"; done
miaou_debug "</save_stacktrace_to_stderr>"
}
function dump_stacktrace {
miaou_debug "<stacktrace count=${#error_source[@]}>"
local i source lineno funcname
@@ -354,12 +368,12 @@ function on_exit {
elif [[ -v failure_type && "$failure_type" == 'COMMAND_NOT_FOUND' ]]; then
unset 'tmp_error[-1]' 'tmp_error[-1]'
add_miaou_error "${BASH_SOURCE[2]}" "${BASH_LINENO[1]}" "${failure_code}" "${failure_type}" "${failure_payload}"
miaou_debug '<command_not_found change_stderr />'
miaou_debug "<command_not_found change_stderr count=${#tmp_error[@]}/>"
elif [[ -v failure_type && "$failure_type" == 'FILE_NOT_FOUND' ]]; then
unset 'tmp_error[-1]' 'tmp_error[-1]'
add_miaou_error "${BASH_SOURCE[2]}" "${BASH_LINENO[1]}" "${failure_code}" "${failure_type}" "${failure_payload}"
miaou_debug '<file_not_found change_stderr />'
miaou_debug "<file_not_found change_stderr count=${#tmp_error[@]}/>"
elif [[ ! -v failure_type ]]; then
if [[ $failure_code -gt 0 && ${#tmp_error[@]} -gt 0 ]]; then
@@ -406,13 +420,18 @@ function on_exit {
fi
fi
2>&3 >&3 dump_stderr
if [[ -v failure_type ]]; then
2>&3 >&4 dump_failure
if [[ -v error_source ]]; then
2>&3 >&4 dump_stacktrace
if ! is_true $CHILD_PROCESS; then
2>&3 >&3 dump_stderr
if [[ -v failure_type ]]; then
2>&3 >&4 dump_failure
if [[ -v error_source ]]; then
2>&3 >&4 dump_stacktrace
fi
fi
elif [[ -v failure_type ]]; then
2>&3 >&4 save_err_trace_to_main
fi
if [[ $failure_code -gt 0 ]]; then
miaou_debug "</on_exit code=$failure_code>"
else
@@ -431,6 +450,7 @@ function build_miaou_bash_error {
mkdir -p "$directory"
if is_true $CHILD_PROCESS; then
MIAOU_BASH_ERROR="${directory}/${PPID}.$$.tmp"
MIAOU_BASH_ERROR_CHILDREN="${directory}/${PPID}.children.tmp"
else
MIAOU_BASH_ERROR="${directory}/$$.tmp"
fi
@@ -440,9 +460,11 @@ function build_miaou_bash_error {
}
function cleanup {
miaou_debug '<cleanup/>'
# trap - ERR EXIT PIPE RETURN
# rm "$MIAOU_BASH_ERROR"
if ! is_true $CHILD_PROCESS; then
miaou_debug '<cleanup main/>'
trap - ERR EXIT PIPE RETURN
# rm "$MIAOU_BASH_ERROR"
fi
}
## main
@@ -459,8 +481,14 @@ trap 'on_exit $?' EXIT
trap 'on_pipe' PIPE
trap 'on_return' RETURN
if [[ -e /proc/$$/fd/3 ]]; then exec 4>&3 3>&-; else exec 4>/dev/tty; fi # swap fd 3 4 when fd 3 sent off
exec 3>/dev/stderr 2>"$MIAOU_BASH_ERROR"
if ! is_true "$CHILD_PROCESS"; then
# main
[[ -e /proc/$$/fd/3 ]] && exec 4>&3 3>&- || exec 4>/dev/tty # swap fd 3 4 when fd 3 sent off
exec 3>/dev/stderr 2>"$MIAOU_BASH_ERROR"
else
# any children
exec 4>/dev/tty 2>"$MIAOU_BASH_ERROR"
fi
if is_true "$CHILD_PROCESS"; then
miaou_debug "<child file=$BASH_ARGV0 pid=${BASHPID} parent=${PPID}>"