diff --git a/misc/core.func b/misc/core.func index 011864a1..bfa597bd 100644 --- a/misc/core.func +++ b/misc/core.func @@ -193,18 +193,16 @@ SILENT_LOGFILE="/tmp/silent.$$.log" silent() { local cmd="$*" - - trap - ERR + set +Eeuo pipefail "$@" >>"$SILENT_LOGFILE" 2>&1 local rc=$? - trap 'error_handler' ERR + set -Eeuo pipefail if [[ $rc -ne 0 ]]; then - BASH_COMMAND="$cmd" - error_handler "$rc" + # Store real command in a helper variable + LAST_SILENT_CMD="$cmd" + return $rc # let ERR trap fire fi - - return $rc } # Check if the shell is using bash diff --git a/misc/error_handler.func b/misc/error_handler.func index fc39f6a4..d370cb56 100644 --- a/misc/error_handler.func +++ b/misc/error_handler.func @@ -82,10 +82,9 @@ 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}} - # clean up cosmetic STD variable command="${command//\$STD/}" if [[ "$exit_code" -eq 0 ]]; then