|
|
@ -287,6 +287,20 @@ function dump_failure { |
|
|
miaou_debug '</error_box>' |
|
|
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 { |
|
|
function dump_stacktrace { |
|
|
miaou_debug "<stacktrace count=${#error_source[@]}>" |
|
|
miaou_debug "<stacktrace count=${#error_source[@]}>" |
|
|
local i source lineno funcname |
|
|
local i source lineno funcname |
|
|
@ -354,12 +368,12 @@ function on_exit { |
|
|
elif [[ -v failure_type && "$failure_type" == 'COMMAND_NOT_FOUND' ]]; then |
|
|
elif [[ -v failure_type && "$failure_type" == 'COMMAND_NOT_FOUND' ]]; then |
|
|
unset 'tmp_error[-1]' 'tmp_error[-1]' |
|
|
unset 'tmp_error[-1]' 'tmp_error[-1]' |
|
|
add_miaou_error "${BASH_SOURCE[2]}" "${BASH_LINENO[1]}" "${failure_code}" "${failure_type}" "${failure_payload}" |
|
|
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 |
|
|
elif [[ -v failure_type && "$failure_type" == 'FILE_NOT_FOUND' ]]; then |
|
|
unset 'tmp_error[-1]' 'tmp_error[-1]' |
|
|
unset 'tmp_error[-1]' 'tmp_error[-1]' |
|
|
add_miaou_error "${BASH_SOURCE[2]}" "${BASH_LINENO[1]}" "${failure_code}" "${failure_type}" "${failure_payload}" |
|
|
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 |
|
|
elif [[ ! -v failure_type ]]; then |
|
|
if [[ $failure_code -gt 0 && ${#tmp_error[@]} -gt 0 ]]; then |
|
|
if [[ $failure_code -gt 0 && ${#tmp_error[@]} -gt 0 ]]; then |
|
|
@ -406,6 +420,7 @@ function on_exit { |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
if ! is_true $CHILD_PROCESS; then |
|
|
2>&3 >&3 dump_stderr |
|
|
2>&3 >&3 dump_stderr |
|
|
if [[ -v failure_type ]]; then |
|
|
if [[ -v failure_type ]]; then |
|
|
2>&3 >&4 dump_failure |
|
|
2>&3 >&4 dump_failure |
|
|
@ -413,6 +428,10 @@ function on_exit { |
|
|
2>&3 >&4 dump_stacktrace |
|
|
2>&3 >&4 dump_stacktrace |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
|
|
|
elif [[ -v failure_type ]]; then |
|
|
|
|
|
2>&3 >&4 save_err_trace_to_main |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
if [[ $failure_code -gt 0 ]]; then |
|
|
if [[ $failure_code -gt 0 ]]; then |
|
|
miaou_debug "</on_exit code=$failure_code>" |
|
|
miaou_debug "</on_exit code=$failure_code>" |
|
|
else |
|
|
else |
|
|
@ -431,6 +450,7 @@ function build_miaou_bash_error { |
|
|
mkdir -p "$directory" |
|
|
mkdir -p "$directory" |
|
|
if is_true $CHILD_PROCESS; then |
|
|
if is_true $CHILD_PROCESS; then |
|
|
MIAOU_BASH_ERROR="${directory}/${PPID}.$$.tmp" |
|
|
MIAOU_BASH_ERROR="${directory}/${PPID}.$$.tmp" |
|
|
|
|
|
MIAOU_BASH_ERROR_CHILDREN="${directory}/${PPID}.children.tmp" |
|
|
else |
|
|
else |
|
|
MIAOU_BASH_ERROR="${directory}/$$.tmp" |
|
|
MIAOU_BASH_ERROR="${directory}/$$.tmp" |
|
|
fi |
|
|
fi |
|
|
@ -440,9 +460,11 @@ function build_miaou_bash_error { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function cleanup { |
|
|
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" |
|
|
# rm "$MIAOU_BASH_ERROR" |
|
|
|
|
|
fi |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
## main |
|
|
## main |
|
|
@ -459,8 +481,14 @@ trap 'on_exit $?' EXIT |
|
|
trap 'on_pipe' PIPE |
|
|
trap 'on_pipe' PIPE |
|
|
trap 'on_return' RETURN |
|
|
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 |
|
|
|
|
|
|
|
|
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" |
|
|
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 |
|
|
if is_true "$CHILD_PROCESS"; then |
|
|
miaou_debug "<child file=$BASH_ARGV0 pid=${BASHPID} parent=${PPID}>" |
|
|
miaou_debug "<child file=$BASH_ARGV0 pid=${BASHPID} parent=${PPID}>" |
|
|
|