almost fix return 0
This commit is contained in:
+11
-16
@@ -39,7 +39,6 @@ function on_return {
|
|||||||
if [[ "${BASH_COMMAND}" == 'return '* ]]; then
|
if [[ "${BASH_COMMAND}" == 'return '* ]]; then
|
||||||
code=$(echo "${BASH_COMMAND}" | cut -d' ' -f2)
|
code=$(echo "${BASH_COMMAND}" | cut -d' ' -f2)
|
||||||
if [[ -n "$code" ]] && [[ "$code" -ne 0 ]]; then
|
if [[ -n "$code" ]] && [[ "$code" -ne 0 ]]; then
|
||||||
trap - DEBUG
|
|
||||||
>&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: return $code from ${FUNCNAME[1]}"
|
>&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: return $code from ${FUNCNAME[1]}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -49,6 +48,7 @@ function on_exit {
|
|||||||
code=${1:-0}
|
code=${1:-0}
|
||||||
|
|
||||||
if [[ $code -gt 0 ]]; then
|
if [[ $code -gt 0 ]]; then
|
||||||
|
|
||||||
stack_lines=("${BASH_LINENO[@]}")
|
stack_lines=("${BASH_LINENO[@]}")
|
||||||
stack_functions=("${FUNCNAME[@]}")
|
stack_functions=("${FUNCNAME[@]}")
|
||||||
stack_sources=("${BASH_SOURCE[@]}")
|
stack_sources=("${BASH_SOURCE[@]}")
|
||||||
@@ -91,7 +91,7 @@ function on_exit {
|
|||||||
failure_payload="${BASH_REMATCH[2]}"
|
failure_payload="${BASH_REMATCH[2]}"
|
||||||
fi
|
fi
|
||||||
last_error="${BASH_SOURCE[1]}:${BASH_LINENO[0]} subshell term $code"
|
last_error="${BASH_SOURCE[1]}:${BASH_LINENO[0]} subshell term $code"
|
||||||
printf "\r"
|
printf "\r" # useful!
|
||||||
kill -USR1 $$
|
kill -USR1 $$
|
||||||
else
|
else
|
||||||
failure_type='UNKNOWN'
|
failure_type='UNKNOWN'
|
||||||
@@ -192,7 +192,7 @@ function on_exit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function miaou_debug {
|
function miaou_debug {
|
||||||
is_true "${MIAOU_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true
|
is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "*********** DEBUG: $*" || true
|
||||||
}
|
}
|
||||||
|
|
||||||
function ansi_block_continuation {
|
function ansi_block_continuation {
|
||||||
@@ -204,24 +204,22 @@ function ansi_block_continuation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ansi_block_error {
|
function ansi_block_error {
|
||||||
BG=RED
|
|
||||||
FG=BLACK
|
FG=BLACK
|
||||||
|
BG=RED
|
||||||
PADDING=2
|
PADDING=2
|
||||||
|
|
||||||
local content detail exit_code
|
local content detail exit_code
|
||||||
|
|
||||||
content=$(style_ansi "$1")
|
content=$(style_ansi "$1")
|
||||||
content=$(style_padding "$content")
|
content=$(style_padding "$content")
|
||||||
|
|
||||||
detail="$2"
|
detail="$2"
|
||||||
[[ -n "$detail" ]] && detail=$(BG=BLACK FG=WHITE style_padding "$2")
|
[[ -n "$detail" ]] && detail=$(BG=BLACK FG=WHITE PADDING_LEFT=4 style_padding "$2")
|
||||||
|
|
||||||
exit_code=$(FG=CYAN style_ansi "$3")
|
exit_code=$(FG=CYAN style_ansi "$3")
|
||||||
printf "\r"
|
builtin echo -en "\r"
|
||||||
BLOCK_CONTINUATION_COL=5 style_block "$content$detail$exit_code"
|
BLOCK_CONTINUATION_COL=5 style_block "$content$detail$exit_code"
|
||||||
ansi_reset
|
ansi_reset
|
||||||
FG=RED style_ansi " ║"
|
FG=RED style_ansi " ║" && builtin echo
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ansi_traces {
|
function ansi_traces {
|
||||||
@@ -243,22 +241,19 @@ function ansi_traces {
|
|||||||
function dump_failure {
|
function dump_failure {
|
||||||
declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
|
declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
|
||||||
dump_stderr true
|
dump_stderr true
|
||||||
|
|
||||||
|
miaou_debug "---error box ${failure_type:-} ---"
|
||||||
if [[ ${failure_type} == 'SUBSHELL SOURCE NOT FOUND' ]]; then
|
if [[ ${failure_type} == 'SUBSHELL SOURCE NOT FOUND' ]]; then
|
||||||
:
|
:
|
||||||
else
|
|
||||||
miaou_debug '---error---'
|
|
||||||
if [[ $failure_type == 'SUBSHELL ERROR' ]]; then
|
|
||||||
>&4 echo -e "${failure_payload}"
|
|
||||||
else
|
else
|
||||||
>&4 ansi_block_error "$failure_type" "$failure_payload" "$code"
|
>&4 ansi_block_error "$failure_type" "$failure_payload" "$code"
|
||||||
fi
|
fi
|
||||||
miaou_debug '---end of error---'
|
miaou_debug '---end of error box---'
|
||||||
fi
|
|
||||||
|
|
||||||
miaou_debug '---stacktrace---'
|
miaou_debug '---stacktrace---'
|
||||||
>&4 ansi_traces stack_sources stack_lines stack_functions
|
>&4 ansi_traces stack_sources stack_lines stack_functions
|
||||||
|
|
||||||
miaou_debug '---end of stacktrace---'
|
miaou_debug '---end of stacktrace---'
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-12
@@ -26,14 +26,14 @@ FG_COLORS[GRAY]='\e[90m'
|
|||||||
FG_COLORS[MAGENTA]='\e[95m'
|
FG_COLORS[MAGENTA]='\e[95m'
|
||||||
|
|
||||||
declare -A BG_COLORS
|
declare -A BG_COLORS
|
||||||
BG_COLORS["BLACK"]='\e[40m'
|
BG_COLORS[BLACK]='\e[40m'
|
||||||
BG_COLORS["RED"]='\e[41m'
|
BG_COLORS[RED]='\e[41m'
|
||||||
BG_COLORS["GREEN"]='\e[42m'
|
BG_COLORS[GREEN]='\e[42m'
|
||||||
BG_COLORS["YELLOW"]='\e[43m'
|
BG_COLORS[YELLOW]='\e[43m'
|
||||||
BG_COLORS["BLUE"]='\e[44m'
|
BG_COLORS[BLUE]='\e[44m'
|
||||||
BG_COLORS["PURPLE"]='\e[45m'
|
BG_COLORS[PURPLE]='\e[45m'
|
||||||
BG_COLORS["CYAN"]='\e[46m'
|
BG_COLORS[CYAN]='\e[46m'
|
||||||
BG_COLORS["WHITE"]='\e[47m'
|
BG_COLORS[WHITE]='\e[47m'
|
||||||
# BG_COLORS["GRAY"]='\e[90m'
|
# BG_COLORS["GRAY"]='\e[90m'
|
||||||
# BG_COLORS["MAGENTA"]='\e[95m'
|
# BG_COLORS["MAGENTA"]='\e[95m'
|
||||||
|
|
||||||
@@ -59,7 +59,6 @@ function style_padding {
|
|||||||
style_ansi "$left"
|
style_ansi "$left"
|
||||||
|
|
||||||
style_ansi "$1"
|
style_ansi "$1"
|
||||||
# builtin echo -n "$1"
|
|
||||||
|
|
||||||
right=$(for _ in $(seq 1 "${padding_right}"); do builtin echo -n ' '; done)
|
right=$(for _ in $(seq 1 "${padding_right}"); do builtin echo -n ' '; done)
|
||||||
style_ansi "$right"
|
style_ansi "$right"
|
||||||
@@ -75,9 +74,7 @@ function _style_variant {
|
|||||||
|
|
||||||
function _style_bg {
|
function _style_bg {
|
||||||
if [[ -n "$1" ]]; then
|
if [[ -n "$1" ]]; then
|
||||||
[[ -v BG_COLORS[$1] ]] && echo "${BG_COLORS[$1]}" && return
|
[[ -v BG_COLORS[$1] ]] && echo "${BG_COLORS[$1]}" || >&2 echo "unknown BG value: $1"
|
||||||
>&2 echo "unknown BG value: $1" && return 1
|
|
||||||
# false
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +90,7 @@ function style_ansi {
|
|||||||
|
|
||||||
function style_block {
|
function style_block {
|
||||||
local content length top bottom i
|
local content length top bottom i
|
||||||
|
|
||||||
content=$(style_padding "$1")
|
content=$(style_padding "$1")
|
||||||
length=$(ansi_length "$content")
|
length=$(ansi_length "$content")
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ stack_functions=('f2' 'f1' '<main>')
|
|||||||
# tput rc
|
# tput rc
|
||||||
# FG=RED style_ansi "\t║\n"
|
# FG=RED style_ansi "\t║\n"
|
||||||
# }
|
# }
|
||||||
function strip_ansi {
|
|
||||||
echo "$1" | sed -E 's/\x1b\[[0-9;]*[a-zA-Z]//g'
|
|
||||||
}
|
|
||||||
function ansi_block_error {
|
function ansi_block_error {
|
||||||
BG=RED
|
BG=RED
|
||||||
FG=BLACK
|
FG=BLACK
|
||||||
@@ -62,10 +60,5 @@ declare -F style_ansi >/dev/null || source "$MIAOU_BASH_DIR/lib/ansi.bash"
|
|||||||
|
|
||||||
echo START
|
echo START
|
||||||
|
|
||||||
output=$(BG=RED style_ansi "╔")
|
echo -n "standard flow:" && show_error
|
||||||
output=$(strip_ansi "$output")
|
|
||||||
echo "$output"
|
|
||||||
# echo "$output" | cat -v
|
|
||||||
|
|
||||||
# echo -n "standard flow:" && show_error
|
|
||||||
# echo -n "starting subshell: $(show_error)"
|
# echo -n "starting subshell: $(show_error)"
|
||||||
|
|||||||
Reference in New Issue
Block a user