diff --git a/misc/core.func b/misc/core.func index bfa597bd..985685a1 100644 --- a/misc/core.func +++ b/misc/core.func @@ -199,10 +199,10 @@ silent() { set -Eeuo pipefail if [[ $rc -ne 0 ]]; then - # Store real command in a helper variable - LAST_SILENT_CMD="$cmd" - return $rc # let ERR trap fire + error_handler "$rc" "$cmd" fi + + return $rc } # Check if the shell is using bash diff --git a/misc/error_handler.func b/misc/error_handler.func index d370cb56..edbf6f1a 100644 --- a/misc/error_handler.func +++ b/misc/error_handler.func @@ -82,8 +82,8 @@ explain_exit_code() { # === Error handler ============================================================ error_handler() { local exit_code=${1:-$?} + local command=${2:-${BASH_COMMAND:-unknown}} local line_number=${BASH_LINENO[0]:-unknown} - local command=${LAST_SILENT_CMD:-${BASH_COMMAND:-unknown}} command="${command//\$STD/}" @@ -95,7 +95,7 @@ error_handler() { explanation="$(explain_exit_code "$exit_code")" printf "\e[?25h" - echo -e "\n${RD}[ERROR]${CL} in line ${RD}${line_number}${CL}: exit code ${RD}${exit_code}${CL} (${explanation}): while executing command ${YW}${command}${CL}\n" + echo -e "\n${RD}[ERROR]${CL} in line ${RD}${line_number}${CL}: exit code ${RD}${exit_code}${CL} (${explanation}): while executing command ${YWB}${command}${CL}\n" if [[ -n "${DEBUG_LOGFILE:-}" ]]; then {