failure_type early detection
This commit is contained in:
@@ -13,14 +13,15 @@ function is_true {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function miaou_debug {
|
function miaou_debug {
|
||||||
is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "\e[90mDEBUG <==> \e[95m$*\e[0m" || true
|
is_true "${MIAOU_DEBUG}" && >/dev/tty builtin echo -e "\r\e[90mDEBUG <==> \e[95m$*\e[0m" || true
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_error {
|
function on_error {
|
||||||
code="${1:-100}"
|
code="${1:-100}"
|
||||||
miaou_debug on_error: $$ $BASHPID
|
miaou_debug "on_error: $code ($$ -- $BASHPID)"
|
||||||
if [[ $$ == "$BASHPID" ]]; then
|
if [[ $$ == "$BASHPID" ]]; then
|
||||||
>&2 echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: command_error: ${code}"
|
>&2 echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: command_error: ${code}"
|
||||||
|
failure_type="COMMAND_ERROR"
|
||||||
exit "$code"
|
exit "$code"
|
||||||
else
|
else
|
||||||
>&2 echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: subshell_error: ${code}"
|
>&2 echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: subshell_error: ${code}"
|
||||||
@@ -28,16 +29,20 @@ function on_error {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_exit {
|
function dump_stderr {
|
||||||
code="${1:-0}"
|
>&2 printf '' # flush
|
||||||
|
|
||||||
miaou_debug --stderr--
|
miaou_debug --stderr--
|
||||||
mapfile -t tmp_error <"$MIAOU_BASH_ERROR"
|
mapfile -t tmp_error <"$MIAOU_BASH_ERROR"
|
||||||
for i in "${tmp_error[@]}"; do >&4 echo -e "$i"; done
|
for i in "${tmp_error[@]}"; do >&4 echo -e "$i"; done
|
||||||
last_error="${tmp_error[-1]}"
|
|
||||||
miaou_debug --end of stderr--
|
miaou_debug --end of stderr--
|
||||||
|
}
|
||||||
|
|
||||||
miaou_debug "on_exit $code"
|
function on_exit {
|
||||||
|
code="${1:-0}"
|
||||||
|
failure_type="${failure_type:-UNDEFINED}"
|
||||||
|
|
||||||
|
dump_stderr
|
||||||
|
miaou_debug "on_exit $code $failure_type"
|
||||||
}
|
}
|
||||||
|
|
||||||
function on_pipe {
|
function on_pipe {
|
||||||
@@ -47,7 +52,7 @@ function on_pipe {
|
|||||||
mapfile -t tmp_error <"$MIAOU_BASH_ERROR"
|
mapfile -t tmp_error <"$MIAOU_BASH_ERROR"
|
||||||
last_error="${tmp_error[-1]}"
|
last_error="${tmp_error[-1]}"
|
||||||
regex='.*: line [0-9]+: subshell_error: ([0-9]+)'
|
regex='.*: line [0-9]+: subshell_error: ([0-9]+)'
|
||||||
[[ $last_error =~ $regex ]] && code=${BASH_REMATCH[1]}
|
[[ $last_error =~ $regex ]] && code=${BASH_REMATCH[1]} && failure_type="SUBSHELL_ERROR"
|
||||||
|
|
||||||
miaou_debug on_pipe: "${code}"
|
miaou_debug on_pipe: "${code}"
|
||||||
exit "$code"
|
exit "$code"
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ function do_subshell_term {
|
|||||||
|
|
||||||
echo toto
|
echo toto
|
||||||
# echo 'toto' | grep none
|
# echo 'toto' | grep none
|
||||||
|
# echo 'toto' | return 3
|
||||||
|
|
||||||
echo -n "found1=$(grep nope nope)"
|
echo -n "found1=$(grep nope nope)"
|
||||||
echo "found1=$(grep nope nope | grep none)"
|
echo "found1=$(grep nope nope | grep none)"
|
||||||
|
|||||||
Reference in New Issue
Block a user