This commit is contained in:
CanbiZ 2025-09-16 10:41:55 +02:00
parent 67ebb3782c
commit ba51df5bb1
2 changed files with 9 additions and 5 deletions

View File

@ -193,13 +193,17 @@ SILENT_LOGFILE="/tmp/silent.$$.log"
silent() {
local cmd="$*"
set +Eeuo pipefail
trap - ERR
"$@" >>"$SILENT_LOGFILE" 2>&1
local rc=$?
set -Eeuo pipefail
trap 'error_handler' ERR
if [[ $rc -ne 0 ]]; then
error_handler "$rc" "$cmd"
BASH_COMMAND="$cmd"
error_handler "$rc"
fi
return $rc
}

View File

@ -85,6 +85,7 @@ error_handler() {
local command=${2:-${BASH_COMMAND:-unknown}}
local line_number=${BASH_LINENO[0]:-unknown}
# clean up cosmetic STD variable
command="${command//\$STD/}"
if [[ "$exit_code" -eq 0 ]]; then
@ -95,7 +96,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 ${YWB}${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 ${YW}${command}${CL}\n"
if [[ -n "${DEBUG_LOGFILE:-}" ]]; then
{
@ -108,7 +109,6 @@ error_handler() {
} >>"$DEBUG_LOGFILE"
fi
# Silent-Log
if [[ -n "${SILENT_LOGFILE:-}" && -s "$SILENT_LOGFILE" ]]; then
echo "--- Last 20 lines of silent log ($SILENT_LOGFILE) ---"
tail -n 20 "$SILENT_LOGFILE"