populate_error_arrays
This commit is contained in:
@@ -189,6 +189,17 @@ function on_error {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function populate_error_arrays {
|
||||||
|
|
||||||
|
local source=$1 line=$2 payload=$3
|
||||||
|
unset 'error_source[0]' 'error_lineno[0]' 'error_funcname[0]'
|
||||||
|
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]'
|
||||||
|
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]'
|
||||||
|
error_source=("$source" "${error_source[@]}")
|
||||||
|
error_lineno=("$line" "${error_lineno[@]}")
|
||||||
|
error_funcname=("${error_funcname[@]}" '<main>')
|
||||||
|
}
|
||||||
|
|
||||||
function on_pipe {
|
function on_pipe {
|
||||||
trap - RETURN
|
trap - RETURN
|
||||||
local tmp_error regex source lineno
|
local tmp_error regex source lineno
|
||||||
@@ -251,7 +262,7 @@ function dump_failure {
|
|||||||
echo -n '╚'
|
echo -n '╚'
|
||||||
for ((i = 0; i < length_box; i++)); do echo -n '═'; done
|
for ((i = 0; i < length_box; i++)); do echo -n '═'; done
|
||||||
echo '╝'
|
echo '╝'
|
||||||
miaou_debug '<continuation disable/>'
|
miaou_debug '<continuation disabled/>'
|
||||||
else
|
else
|
||||||
echo -n '╚'
|
echo -n '╚'
|
||||||
for ((i = 0; i < 4; i++)); do echo -n '═'; done
|
for ((i = 0; i < 4; i++)); do echo -n '═'; done
|
||||||
@@ -259,7 +270,7 @@ function dump_failure {
|
|||||||
for ((i = 5; i < length_box; i++)); do echo -n '═'; done
|
for ((i = 5; i < length_box; i++)); do echo -n '═'; done
|
||||||
echo '╝'
|
echo '╝'
|
||||||
echo " ║"
|
echo " ║"
|
||||||
miaou_debug '<continuation enable/>'
|
miaou_debug '<continuation enabled/>'
|
||||||
fi
|
fi
|
||||||
tty_ansi RESET
|
tty_ansi RESET
|
||||||
miaou_debug '</error_box>'
|
miaou_debug '</error_box>'
|
||||||
@@ -330,30 +341,39 @@ function on_exit {
|
|||||||
|
|
||||||
regex='^(.*): line ([0-9]+): (.*): unbound variable$'
|
regex='^(.*): line ([0-9]+): (.*): unbound variable$'
|
||||||
if [[ $failure_code -eq 1 ]] && [[ "$last_error" =~ $regex ]]; then
|
if [[ $failure_code -eq 1 ]] && [[ "$last_error" =~ $regex ]]; then
|
||||||
local source line payload
|
failure_type='UNBOUND_VARIABLE'
|
||||||
|
failure_payload="${BASH_REMATCH[3]}"
|
||||||
|
failure_code=2
|
||||||
|
|
||||||
source="${BASH_REMATCH[1]}"
|
local source="${BASH_REMATCH[1]}" line="${BASH_REMATCH[2]}"
|
||||||
line="${BASH_REMATCH[2]}"
|
|
||||||
payload="${BASH_REMATCH[3]}"
|
|
||||||
error_source=("${BASH_SOURCE[@]}")
|
error_source=("${BASH_SOURCE[@]}")
|
||||||
error_lineno=("${BASH_LINENO[@]}")
|
error_lineno=("${BASH_LINENO[@]}")
|
||||||
error_funcname=("${FUNCNAME[@]}")
|
error_funcname=("${FUNCNAME[@]}")
|
||||||
unset 'error_source[0]' 'error_lineno[0]' 'error_funcname[0]'
|
populate_error_arrays "$source" "$line" "$failure_payload"
|
||||||
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]'
|
|
||||||
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]'
|
|
||||||
error_source=("$source" "${error_source[@]}")
|
|
||||||
error_lineno=("$line" "${error_lineno[@]}")
|
|
||||||
error_funcname=("${error_funcname[@]}" '<main>')
|
|
||||||
|
|
||||||
failure_code=$failure_code
|
|
||||||
failure_type='UNBOUND_VARIABLE'
|
|
||||||
failure_payload=$payload
|
|
||||||
|
|
||||||
unset 'tmp_error[-1]'
|
unset 'tmp_error[-1]'
|
||||||
add_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}" "${failure_payload}"
|
add_miaou_error "$source" "$line" "${failure_code}" "${failure_type}" "${failure_payload}"
|
||||||
miaou_debug "<unbound_variable source=${source} line=${line} payload=${failure_payload}/>"
|
miaou_debug "<unbound_variable source=${source} line=${line} payload=${failure_payload}/>"
|
||||||
else
|
else
|
||||||
failure_type='UNKNOWN ERROR'
|
regex='^(.*): line ([0-9]+): (.*): No such file or directory$'
|
||||||
|
if [[ $failure_code -eq 1 ]] && [[ "$last_error" =~ $regex ]]; then
|
||||||
|
failure_type='SOURCE_NOT_FOUND'
|
||||||
|
failure_payload="${BASH_REMATCH[3]}"
|
||||||
|
failure_code=3
|
||||||
|
|
||||||
|
local source="${BASH_REMATCH[1]}" line="${BASH_REMATCH[2]}"
|
||||||
|
error_source=("${BASH_SOURCE[@]}")
|
||||||
|
error_lineno=("${BASH_LINENO[@]}")
|
||||||
|
error_funcname=("${FUNCNAME[@]}")
|
||||||
|
populate_error_arrays "$source" "$line" "$failure_payload"
|
||||||
|
|
||||||
|
unset 'tmp_error[-1]'
|
||||||
|
add_miaou_error "$source" "$line" "${failure_code}" "${failure_type}" "${failure_payload}"
|
||||||
|
miaou_debug "<source_not_found source=${source} line=${line} payload=${failure_payload}/>"
|
||||||
|
else
|
||||||
|
failure_type='UNKNOWN ERROR'
|
||||||
|
failure_payload="$BASH_COMMAND"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
miaou_debug "</investigate_tmp_error>"
|
miaou_debug "</investigate_tmp_error>"
|
||||||
fi
|
fi
|
||||||
@@ -367,7 +387,7 @@ function on_exit {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ $failure_code -gt 0 ]]; then
|
if [[ $failure_code -gt 0 ]]; then
|
||||||
miaou_debug "</on_exit failure>"
|
miaou_debug "</on_exit code=$failure_code>"
|
||||||
else
|
else
|
||||||
miaou_debug "</on_exit success>"
|
miaou_debug "</on_exit success>"
|
||||||
fi
|
fi
|
||||||
|
|||||||
+1
-1
@@ -55,7 +55,7 @@ fail_type last_false COMMAND_ERROR
|
|||||||
fail_type subshell_term SUBSHELL_ERROR
|
fail_type subshell_term SUBSHELL_ERROR
|
||||||
fail_type exit EXIT
|
fail_type exit EXIT
|
||||||
fail_type command_not_found COMMAND_NOT_FOUND
|
fail_type command_not_found COMMAND_NOT_FOUND
|
||||||
# fail_type source_not_found SOURCE_NOT_FOUND
|
fail_type source_not_found SOURCE_NOT_FOUND
|
||||||
# fail_type file_not_found FILE_NOT_FOUND
|
# fail_type file_not_found FILE_NOT_FOUND
|
||||||
# fail_type subshell_error COMMAND_NOT_FOUND '(hint: prefer source than subshell)'
|
# fail_type subshell_error COMMAND_NOT_FOUND '(hint: prefer source than subshell)'
|
||||||
# fail_type command_error COMMAND_ERROR
|
# fail_type command_error COMMAND_ERROR
|
||||||
|
|||||||
Reference in New Issue
Block a user