This commit is contained in:
CanbiZ 2025-09-16 10:49:47 +02:00
parent ba51df5bb1
commit cb29e50080
2 changed files with 6 additions and 9 deletions

View File

@ -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

View File

@ -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