diff --git a/bin/miaou-bash b/bin/miaou-bash
index 45dd88b..6b7b4c9 100755
--- a/bin/miaou-bash
+++ b/bin/miaou-bash
@@ -287,6 +287,20 @@ function dump_failure {
miaou_debug ''
}
+function save_err_trace_to_main {
+ miaou_debug ""
+ 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 ""
+ >>"$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 ""
+}
+
function dump_stacktrace {
miaou_debug ""
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 ''
+ miaou_debug ""
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 ''
+ miaou_debug ""
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 ""
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 ''
- # trap - ERR EXIT PIPE RETURN
- # rm "$MIAOU_BASH_ERROR"
+ if ! is_true $CHILD_PROCESS; then
+ miaou_debug ''
+ 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 ""
diff --git a/test/stub/extra/library.bash b/test/stub/extra/library.bash
index 3f996ec..daa2191 100755
--- a/test/stub/extra/library.bash
+++ b/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
diff --git a/test/stub/scenario.bash b/test/stub/scenario.bash
index 73953f6..946000f 100755
--- a/test/stub/scenario.bash
+++ b/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 {