Browse Source

not yet children

main
pvincent 2 weeks ago
parent
commit
b989cc012c
  1. 40
      bin/miaou-bash
  2. 22
      test/stub/extra/library.bash
  3. 3
      test/stub/scenario.bash

40
bin/miaou-bash

@ -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,6 +420,7 @@ function on_exit {
fi
fi
if ! is_true $CHILD_PROCESS; then
2>&3 >&3 dump_stderr
if [[ -v failure_type ]]; then
2>&3 >&4 dump_failure
@ -413,6 +428,10 @@ function on_exit {
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
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}>"

22
test/stub/extra/library.bash

@ -1,22 +1,12 @@
#!/usr/bin/env miaou-bash
#!/usr/bin/env bash
function blabla {
echo IN blabla OUT
>&2 echo stderr from utility
# . lib/not_found_again.bash
# lib/not_found_again.bash
suite
}
BASEDIR=$(dirname "$0")
function suite {
command_not_found
grep nope nope
exit
exit 10 # youpi
echo $nope
return 7
return
function library {
echo library loaded
>&2 echo stderr from library
"$BASEDIR/onemore.bash"
}
blabla
library

3
test/stub/scenario.bash

@ -92,8 +92,9 @@ function do_file_not_found {
function do_child_error {
"$BASEDIR/extra/library.bash"
# . "$BASEDIR/extra/library.bash"
echo SHOULD NOT APPEAR
. "$BASEDIR/extra/library.bash"
}
function do_command_error {

Loading…
Cancel
Save