Browse Source

TODO source/file not found

main
pvincent 2 weeks ago
parent
commit
80c3fce399
  1. 68
      bin/miaou-bash

68
bin/miaou-bash

@ -53,7 +53,8 @@ function on_exit {
stack_functions=("${stack_functions[@]}") stack_functions=("${stack_functions[@]}")
stack_sources=("${stack_sources[@]}") stack_sources=("${stack_sources[@]}")
stack_summary=()
failure_traces=()
failure_payload=''
if [[ $code -gt 0 ]]; then if [[ $code -gt 0 ]]; then
last_error=$(tail -n1 "$MIAOU_BASH_ERROR") last_error=$(tail -n1 "$MIAOU_BASH_ERROR")
@ -64,29 +65,59 @@ function on_exit {
if [[ "$last_error" =~ $regex1 || "$last_error" =~ $regex2 ]]; then if [[ "$last_error" =~ $regex1 || "$last_error" =~ $regex2 ]]; then
line=${BASH_REMATCH[1]} line=${BASH_REMATCH[1]}
message=${BASH_REMATCH[2]} message=${BASH_REMATCH[2]}
regex=': unbound variable$'
[[ $code == 1 ]] && [[ "$message" =~ $regex ]] && stack_lines[0]=$line
regex="^return ([0-9]*) from (.*)\$"
if [[ "$message" =~ $regex ]]; then
return_code="${BASH_REMATCH[1]}"
funcname="${BASH_REMATCH[2]}"
# >&4 echo "RETURN DETECTED line ${stack_sources[0]} $line $funcname"
stack_sources=("${stack_sources[0]}" "${stack_sources[@]}")
stack_lines=("$line" "${stack_lines[@]}")
stack_functions=("$funcname" "${stack_functions[@]}")
stack_summary+=("ERROR $code: [return $return_code]")
regex='^(.*): unbound variable$'
if [[ $code == 1 ]] && [[ "$message" =~ $regex ]]; then
failure_type='UNBOUND VARIABLE'
failure_payload="${BASH_REMATCH[1]}"
stack_lines[0]=$line
else else
stack_summary+=("ERROR $code: [$message]")
regex="^return ([0-9]*) from (.*)\$"
if [[ "$message" =~ $regex ]]; then
return_code="${BASH_REMATCH[1]}"
funcname="${BASH_REMATCH[2]}"
# >&4 echo "RETURN DETECTED line ${stack_sources[0]} $line $funcname"
stack_sources=("${stack_sources[0]}" "${stack_sources[@]}")
stack_lines=("$line" "${stack_lines[@]}")
stack_functions=("$funcname" "${stack_functions[@]}")
failure_type='RETURN'
failure_traces+=("ERROR $code: [return $return_code]")
else
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 fi
else else
failure_type='COMMAND'
failure_payload="${last_error}"
regex="^ .*:[0-9]* .*\$" regex="^ .*:[0-9]* .*\$"
[[ "$last_error" =~ $regex ]] || stack_summary+=("ERROR $code:") # <undefined>
[[ "$last_error" =~ $regex ]] || failure_traces+=("ERROR $code:") # <undefined>
fi fi
for i in "${!stack_functions[@]}"; do for i in "${!stack_functions[@]}"; do
stack_detail=$(printf "\t%30s\t%s\n" "${stack_sources[$i]}:${stack_lines[$i]}" "${stack_functions[$i]}") 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 done
dump_failure dump_failure
else else
@ -99,7 +130,10 @@ function on_exit {
function dump_failure { function dump_failure {
dump_stderr true dump_stderr true
$MIAOU_BASH_DEBUG && >/dev/tty echo '---stacktrace---' $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" >&4 echo -e "$i"
done done
cleanup cleanup

Loading…
Cancel
Save