|
|
|
@ -48,6 +48,7 @@ function is_true { |
|
|
|
# example: alias toto="bash -c \"[[ \\\$MIAOU_DEBUG == 'true' ]] && echo yes \\\$* || echo nope\"" |
|
|
|
function miaou_debug { |
|
|
|
if is_true "${MIAOU_DEBUG}"; then |
|
|
|
local saved_bash_rematch=("${BASH_REMATCH[@]}") # important when regex are used before calling miaou_debug |
|
|
|
local i message="$*" padding='' |
|
|
|
local compute_hierarchy=true |
|
|
|
[[ ! -v miaou_debug_hierarchy ]] && miaou_debug_hierarchy=0 |
|
|
|
@ -66,6 +67,7 @@ function miaou_debug { |
|
|
|
[[ "${message}" =~ $regex ]] && |
|
|
|
miaou_debug_hierarchy=$((miaou_debug_hierarchy + 1)) || |
|
|
|
true |
|
|
|
BASH_REMATCH=("${saved_bash_rematch[@]}") # important when regex are used before calling miaou_debug |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
@ -165,12 +167,52 @@ function on_error { |
|
|
|
failure_type='FILE_NOT_FOUND' |
|
|
|
failure_payload="${BASH_REMATCH[3]}" |
|
|
|
miaou_debug "<file_not_found payload=${failure_payload}/>" |
|
|
|
|
|
|
|
elif ! is_true "$CHILD_PROCESS"; then |
|
|
|
# in main process only, not from children! |
|
|
|
local regex2 |
|
|
|
last_error="${tmp_error[-1]}" |
|
|
|
regex2='^[[:space:]]+miaou_trace: source=(.*) lineno=(.*) funcname=(.*)$' |
|
|
|
if [[ "$last_error" =~ $regex2 ]]; then |
|
|
|
trace_source="${BASH_REMATCH[1]}" |
|
|
|
trace_lineno="${BASH_REMATCH[2]}" |
|
|
|
trace_funcname="${BASH_REMATCH[3]}" |
|
|
|
extra_source=("$trace_source") |
|
|
|
extra_lineno=("$trace_lineno") |
|
|
|
extra_funcname=("$trace_funcname") |
|
|
|
miaou_debug "<miaou_trace found_first source=${extra_source} lineno=${extra_lineno} funcname=${extra_funcname}/>" |
|
|
|
# go backward |
|
|
|
for ((i = ${#tmp_error[@]} - 2; i >= 0; i--)); do |
|
|
|
content=${tmp_error[$i]} |
|
|
|
miaou_debug "<index i=$i content=$content>" |
|
|
|
if [[ "$content" =~ $regex2 ]]; then |
|
|
|
source="${BASH_REMATCH[1]}" |
|
|
|
lineno="${BASH_REMATCH[2]}" |
|
|
|
funcname="${BASH_REMATCH[3]}" |
|
|
|
extra_source=("$source" "${extra_source[@]}") |
|
|
|
extra_lineno=("$lineno" "${extra_lineno[@]}") |
|
|
|
extra_funcname=("$funcname" "${extra_funcname[@]}") |
|
|
|
miaou_debug '<miaou_trace found_remainders/>' |
|
|
|
else |
|
|
|
miaou_debug "<search_for_trace last={${last_error}}/>" |
|
|
|
regex='^[[:space:]]*miaou_trace: ' |
|
|
|
if [[ "$last_error" =~ $regex ]]; then |
|
|
|
miaou_debug "<trace found/>" |
|
|
|
#TODO: .. |
|
|
|
regex2='^(.*): line ([0-9]+): miaou_error: (.*) [0-9]+(.*)$' |
|
|
|
if [[ "$content" =~ $regex2 ]]; then |
|
|
|
failure_type='CHILD_ERROR' |
|
|
|
failure_payload="${BASH_REMATCH[3]}" |
|
|
|
local optional_payload |
|
|
|
optional_payload="${BASH_REMATCH[4]}" |
|
|
|
[[ -n "$optional_payload" ]] && |
|
|
|
optional_payload="${optional_payload# payload: }" && |
|
|
|
failure_payload="${failure_payload} ${optional_payload}" |
|
|
|
miaou_debug "<child_error type=${failure_payload} optional={${optional_payload}} found/>" |
|
|
|
else |
|
|
|
miaou_debug '<child_error no_miaou_error weird=true/>' |
|
|
|
fi |
|
|
|
break |
|
|
|
fi |
|
|
|
miaou_debug '</index>' |
|
|
|
done |
|
|
|
miaou_debug "<extra_trace count=${#extra_source[@]}/>" |
|
|
|
miaou_debug "</miaou_trace found>" |
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
@ -185,9 +227,16 @@ function on_error { |
|
|
|
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]' |
|
|
|
unset 'error_source[0]' 'error_lineno[-1]' 'error_funcname[0]' |
|
|
|
error_funcname[-1]='<main>' |
|
|
|
|
|
|
|
if [[ $failure_type == 'CHILD_ERROR' ]]; then |
|
|
|
error_source=("${extra_source[@]}" "${error_source[@]}") |
|
|
|
error_lineno=("${extra_lineno[@]}" "${error_lineno[@]}") |
|
|
|
error_funcname=("${extra_funcname[@]}" "${error_funcname[@]}") |
|
|
|
else |
|
|
|
error_source=("${error_source[@]}") |
|
|
|
error_lineno=("${error_lineno[@]}") |
|
|
|
error_funcname=("${error_funcname[@]}") |
|
|
|
fi |
|
|
|
|
|
|
|
if [[ -v failure_payload ]]; then |
|
|
|
miaou_debug "</on_error exit=$failure_code type=${failure_type} payload={${failure_payload}}>" |
|
|
|
@ -414,6 +463,11 @@ function on_exit { |
|
|
|
add_miaou_error "${BASH_SOURCE[2]}" "${BASH_LINENO[1]}" "${failure_code}" "${failure_type}" "${failure_payload}" |
|
|
|
miaou_debug "<file_not_found change_stderr count=${#tmp_error[@]}/>" |
|
|
|
|
|
|
|
elif [[ -v failure_type && "$failure_type" == 'CHILD_ERROR' ]]; then |
|
|
|
for ((i = 0; i < ${#extra_source[@]}; i++)); do unset 'tmp_error[-1]'; done |
|
|
|
add_miaou_error "${BASH_SOURCE[2]}" "${BASH_LINENO[1]}" "${failure_code}" "${failure_type}" "${failure_payload}" |
|
|
|
miaou_debug "<child_error change_stderr count=${#tmp_error[@]}/>" |
|
|
|
|
|
|
|
elif [[ ! -v failure_type ]]; then |
|
|
|
if [[ $failure_code -gt 0 && ${#tmp_error[@]} -gt 0 ]]; then |
|
|
|
last_error="${tmp_error[-1]}" |
|
|
|
|