TODO source/file not found
This commit is contained in:
+42
-8
@@ -53,7 +53,8 @@ function on_exit {
|
||||
stack_functions=("${stack_functions[@]}")
|
||||
stack_sources=("${stack_sources[@]}")
|
||||
|
||||
stack_summary=()
|
||||
failure_traces=()
|
||||
failure_payload=''
|
||||
|
||||
if [[ $code -gt 0 ]]; then
|
||||
last_error=$(tail -n1 "$MIAOU_BASH_ERROR")
|
||||
@@ -64,8 +65,13 @@ function on_exit {
|
||||
if [[ "$last_error" =~ $regex1 || "$last_error" =~ $regex2 ]]; then
|
||||
line=${BASH_REMATCH[1]}
|
||||
message=${BASH_REMATCH[2]}
|
||||
regex=': unbound variable$'
|
||||
[[ $code == 1 ]] && [[ "$message" =~ $regex ]] && stack_lines[0]=$line
|
||||
|
||||
regex='^(.*): unbound variable$'
|
||||
if [[ $code == 1 ]] && [[ "$message" =~ $regex ]]; then
|
||||
failure_type='UNBOUND VARIABLE'
|
||||
failure_payload="${BASH_REMATCH[1]}"
|
||||
stack_lines[0]=$line
|
||||
else
|
||||
|
||||
regex="^return ([0-9]*) from (.*)\$"
|
||||
if [[ "$message" =~ $regex ]]; then
|
||||
@@ -75,18 +81,43 @@ function on_exit {
|
||||
stack_sources=("${stack_sources[0]}" "${stack_sources[@]}")
|
||||
stack_lines=("$line" "${stack_lines[@]}")
|
||||
stack_functions=("$funcname" "${stack_functions[@]}")
|
||||
stack_summary+=("ERROR $code: [return $return_code]")
|
||||
|
||||
failure_type='RETURN'
|
||||
failure_traces+=("ERROR $code: [return $return_code]")
|
||||
else
|
||||
stack_summary+=("ERROR $code: [$message]")
|
||||
regex='^(.*): command not found$'
|
||||
if [[ "$message" =~ $regex ]]; then
|
||||
failure_type='COMMAND NOT FOUND'
|
||||
failure_payload="${BASH_REMATCH[1]}"
|
||||
else
|
||||
regex='^exit'
|
||||
if [[ "$message" =~ $regex ]]; then
|
||||
failure_type='EXIT'
|
||||
else
|
||||
regex='^(.*): No such file or directory$'
|
||||
if [[ "$message" =~ $regex ]]; then
|
||||
#TODO: SOURCE_NOT_FOUND or FILE_NOT_FOUND
|
||||
failure_type='SOURCE NOT FOUND'
|
||||
failure_payload="${BASH_REMATCH[1]} line=${line}"
|
||||
else
|
||||
failure_type='UNKNOWN'
|
||||
failure_payload="${message}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
failure_traces+=("ERROR $code: [$message]")
|
||||
fi
|
||||
fi
|
||||
else
|
||||
failure_type='COMMAND'
|
||||
failure_payload="${last_error}"
|
||||
regex="^ .*:[0-9]* .*\$"
|
||||
[[ "$last_error" =~ $regex ]] || stack_summary+=("ERROR $code:") # <undefined>
|
||||
[[ "$last_error" =~ $regex ]] || failure_traces+=("ERROR $code:") # <undefined>
|
||||
fi
|
||||
|
||||
for i in "${!stack_functions[@]}"; do
|
||||
stack_detail=$(printf "\t%30s\t%s\n" "${stack_sources[$i]}:${stack_lines[$i]}" "${stack_functions[$i]}")
|
||||
stack_summary+=("$stack_detail")
|
||||
failure_traces+=("$stack_detail")
|
||||
done
|
||||
dump_failure
|
||||
else
|
||||
@@ -99,7 +130,10 @@ function on_exit {
|
||||
function dump_failure {
|
||||
dump_stderr true
|
||||
$MIAOU_BASH_DEBUG && >/dev/tty echo '---stacktrace---'
|
||||
for i in "${stack_summary[@]}"; do
|
||||
>&4 echo "CODE: ${code}"
|
||||
>&4 echo "TYPE: ${failure_type}"
|
||||
>&4 echo "PAYLOAD: ${failure_payload}"
|
||||
for i in "${failure_traces[@]}"; do
|
||||
>&4 echo -e "$i"
|
||||
done
|
||||
cleanup
|
||||
|
||||
Reference in New Issue
Block a user