smarter ansi_error
This commit is contained in:
+50
-7
@@ -188,7 +188,6 @@ function on_exit {
|
|||||||
failure_traces+=("$stack_detail")
|
failure_traces+=("$stack_detail")
|
||||||
done
|
done
|
||||||
dump_failure
|
dump_failure
|
||||||
# builtin exit "$code"
|
|
||||||
else
|
else
|
||||||
dump_success
|
dump_success
|
||||||
fi
|
fi
|
||||||
@@ -199,6 +198,46 @@ function debug {
|
|||||||
is_true "${MIAOU_BASH_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
|
is_true "${MIAOU_BASH_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ansi_block_continuation {
|
||||||
|
tput sc
|
||||||
|
tput cuu 1
|
||||||
|
BG=RED FG=BLACK style_ansi "\t╦"
|
||||||
|
tput rc
|
||||||
|
FG=RED style_ansi "\t║\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
function ansi_block_error {
|
||||||
|
BG=RED
|
||||||
|
FG=BLACK
|
||||||
|
PADDING=2
|
||||||
|
|
||||||
|
local content detail exit_code
|
||||||
|
|
||||||
|
content=$(style_ansi "$1")
|
||||||
|
content=$(style_padding "$content")
|
||||||
|
detail=$(BG=BLACK style_padding "$2")
|
||||||
|
exit_code=$(FG=CYAN style_ansi " $3")
|
||||||
|
style_block "$content$detail$exit_code"
|
||||||
|
|
||||||
|
ansi_reset
|
||||||
|
}
|
||||||
|
|
||||||
|
function ansi_traces {
|
||||||
|
local optional location sources lines functions
|
||||||
|
declare -n sources=$1
|
||||||
|
declare -n lines=$2
|
||||||
|
declare -n functions=$3
|
||||||
|
optional=false
|
||||||
|
for i in "${!sources[@]}"; do
|
||||||
|
FG=RED style_ansi "\t╟─⟶"
|
||||||
|
location="${sources[$i]}:${lines[$i]}"
|
||||||
|
is_true "$optional" &&
|
||||||
|
location=$(FG=GRAY STYLE=ITALIC style_ansi "\t$location") || # FIXME: \t should not be required!
|
||||||
|
location=$(STYLE=ITALIC style_ansi "$location")
|
||||||
|
printf "%40s\t%s\n" "${location}" "${functions[$i]}"
|
||||||
|
optional=true
|
||||||
|
done
|
||||||
|
}
|
||||||
function dump_failure {
|
function dump_failure {
|
||||||
dump_stderr true
|
dump_stderr true
|
||||||
debug '---stacktrace---'
|
debug '---stacktrace---'
|
||||||
@@ -208,14 +247,18 @@ function dump_failure {
|
|||||||
if [[ $failure_type == 'SUBSHELL ERROR' ]]; then
|
if [[ $failure_type == 'SUBSHELL ERROR' ]]; then
|
||||||
>&4 echo -e "${failure_payload}"
|
>&4 echo -e "${failure_payload}"
|
||||||
else
|
else
|
||||||
>&4 echo -e "\tCODE: ${code}"
|
declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
|
||||||
>&4 echo -e "\tTYPE: ${failure_type}"
|
>&4 ansi_block_error "$failure_type" "$failure_payload" "$code"
|
||||||
>&4 echo -e "\tPAYLOAD: ${failure_payload}"
|
>&4 ansi_block_continuation
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
for i in "${failure_traces[@]}"; do
|
|
||||||
>&4 echo -e "$i"
|
declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
|
||||||
done
|
>&4 ansi_traces stack_sources stack_lines stack_functions
|
||||||
|
|
||||||
|
# for i in "${failure_traces[@]}"; do
|
||||||
|
# >&4 echo -e "$i"
|
||||||
|
# done
|
||||||
debug '---end of stacktrace---'
|
debug '---end of stacktrace---'
|
||||||
cleanup
|
cleanup
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-5
@@ -4,6 +4,9 @@
|
|||||||
PADDING=0
|
PADDING=0
|
||||||
ANSI_RESET='\e[0m'
|
ANSI_RESET='\e[0m'
|
||||||
|
|
||||||
|
BLOCK_CONTINUATION_COL=
|
||||||
|
BLOCK_CONTINUATION_SYMBOL=╦
|
||||||
|
|
||||||
declare -A STYLE_VARIANTS
|
declare -A STYLE_VARIANTS
|
||||||
STYLE_VARIANTS[BOLD]='\e[1m'
|
STYLE_VARIANTS[BOLD]='\e[1m'
|
||||||
STYLE_VARIANTS[ITALIC]='\e[3m'
|
STYLE_VARIANTS[ITALIC]='\e[3m'
|
||||||
@@ -88,7 +91,7 @@ function style_ansi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function style_block {
|
function style_block {
|
||||||
local content length top bottom
|
local content length top bottom i
|
||||||
content=$(style_padding "$1")
|
content=$(style_padding "$1")
|
||||||
length=$(ansi_length "$content")
|
length=$(ansi_length "$content")
|
||||||
|
|
||||||
@@ -97,16 +100,22 @@ function style_block {
|
|||||||
for _ in $(seq 1 "${length}"); do builtin echo -n '═'; done
|
for _ in $(seq 1 "${length}"); do builtin echo -n '═'; done
|
||||||
builtin echo "╗"
|
builtin echo "╗"
|
||||||
)
|
)
|
||||||
style_ansi "${top}" && echo
|
style_ansi "${top}" && builtin echo
|
||||||
|
|
||||||
style_ansi "║"
|
style_ansi "║"
|
||||||
style_ansi "${content}"
|
style_ansi "${content}"
|
||||||
style_ansi "║" && echo
|
style_ansi "║" && builtin echo
|
||||||
|
|
||||||
bottom=$(
|
bottom=$(
|
||||||
builtin echo -n "╚"
|
builtin echo -n "╚"
|
||||||
for _ in $(seq 1 "${length}"); do builtin echo -n '═'; done
|
for i in $(seq 1 "${length}"); do
|
||||||
|
if [[ $i == "$BLOCK_CONTINUATION_COL" ]]; then
|
||||||
|
builtin echo -n "$BLOCK_CONTINUATION_SYMBOL"
|
||||||
|
else
|
||||||
|
builtin echo -n '═'
|
||||||
|
fi
|
||||||
|
done
|
||||||
builtin echo "╝"
|
builtin echo "╝"
|
||||||
)
|
)
|
||||||
style_ansi "${bottom}" && echo
|
style_ansi "${bottom}" && builtin echo
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-27
@@ -1,21 +1,19 @@
|
|||||||
#!/usr/bin/env miaou-bash
|
#!/usr/bin/env miaou-bash
|
||||||
|
|
||||||
. "$MIAOU_BASH_DIR/lib/ansi.bash"
|
code=118
|
||||||
|
failure_type='SUBSHELL TERM'
|
||||||
CODE=118
|
failure_payload='blabla'
|
||||||
TYPE='SUBSHELL TERM'
|
|
||||||
PAYLOAD='blabla'
|
|
||||||
stack_sources=('file.bash' './lib/utility.bash' 'file.bash')
|
stack_sources=('file.bash' './lib/utility.bash' 'file.bash')
|
||||||
stack_lines=(18 56 12)
|
stack_lines=(18 56 12)
|
||||||
stack_functions=('f2' 'f1' '<main>')
|
stack_functions=('f2' 'f1' '<main>')
|
||||||
|
|
||||||
function ansi_block_continuation {
|
# function ansi_block_continuation {
|
||||||
tput sc
|
# tput sc
|
||||||
tput cuu 1
|
# tput cuu 1
|
||||||
BG=RED FG=BLACK style_ansi "\t╦"
|
# BG=RED FG=BLACK style_ansi "\t╦"
|
||||||
tput rc
|
# tput rc
|
||||||
FG=RED style_ansi "\t║\n"
|
# FG=RED style_ansi "\t║\n"
|
||||||
}
|
# }
|
||||||
|
|
||||||
function ansi_block_error {
|
function ansi_block_error {
|
||||||
BG=RED
|
BG=RED
|
||||||
@@ -24,30 +22,42 @@ function ansi_block_error {
|
|||||||
|
|
||||||
local content detail exit_code
|
local content detail exit_code
|
||||||
|
|
||||||
content=$(style_ansi "${TYPE}")
|
content=$(style_ansi "$1")
|
||||||
content=$(style_padding "$content")
|
content=$(style_padding "$content")
|
||||||
detail=$(BG=BLACK style_padding "${PAYLOAD}")
|
detail=$(BG=BLACK style_padding "$2")
|
||||||
exit_code=$(FG=WHITE style_ansi " ${CODE}")
|
exit_code=$(FG=CYAN style_ansi " $3")
|
||||||
style_block "$content$detail$exit_code"
|
BLOCK_CONTINUATION_COL=5 style_block "$content$detail$exit_code"
|
||||||
|
|
||||||
ansi_reset
|
ansi_reset
|
||||||
|
FG=RED style_ansi " ║"
|
||||||
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
function ansi_traces {
|
function ansi_traces {
|
||||||
local optional location
|
local optional location sources lines functions
|
||||||
|
declare -n sources=$1
|
||||||
|
declare -n lines=$2
|
||||||
|
declare -n functions=$3
|
||||||
optional=false
|
optional=false
|
||||||
for i in "${!stack_sources[@]}"; do
|
for i in "${!sources[@]}"; do
|
||||||
FG=RED style_ansi "\t╟─⟶"
|
FG=RED style_ansi " ╟─⟶"
|
||||||
location="${stack_sources[$i]}:${stack_lines[$i]}"
|
location=$(printf "%40s" "${sources[$i]}:${lines[$i]}")
|
||||||
is_true "$optional" &&
|
is_true "$optional" &&
|
||||||
location=$(FG=GRAY STYLE=ITALIC style_ansi "\t$location") || # FIXME: \t should not be required!
|
location=$(FG=GRAY STYLE=ITALIC style_ansi "$location") ||
|
||||||
location=$(STYLE=ITALIC style_ansi "$location")
|
location=$(STYLE=ITALIC style_ansi "$location")
|
||||||
printf "%40s\t%s\n" "${location}" "${stack_functions[$i]}"
|
builtin echo "${location} ${functions[$i]}"
|
||||||
optional=true
|
optional=true
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
ansi_block_error
|
function show_error {
|
||||||
ansi_block_continuation
|
>&2 printf '\r'
|
||||||
ansi_traces
|
>&2 ansi_block_error "$failure_type" "$failure_payload" "$code"
|
||||||
|
>&2 ansi_traces stack_sources stack_lines stack_functions
|
||||||
|
# [[ -p /dev/stdout ]] && kill -TERM $$
|
||||||
|
}
|
||||||
|
|
||||||
|
declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
|
||||||
|
|
||||||
|
echo START
|
||||||
|
# echo -n "standard flow:" && show_error
|
||||||
|
echo -n "starting subshell: $(show_error)"
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ readonly BASEDIR
|
|||||||
|
|
||||||
# SCENARII
|
# SCENARII
|
||||||
|
|
||||||
|
function do_subshell_false {
|
||||||
|
result=$(false)
|
||||||
|
}
|
||||||
|
|
||||||
function do_subshell_term {
|
function do_subshell_term {
|
||||||
# grep nope nope
|
# grep nope nope
|
||||||
echo "found=$(command_not_found)"
|
echo "found=$(command_not_found)"
|
||||||
|
|||||||
Reference in New Issue
Block a user