silent(): use return instead of exit to allow || true error handling

Previously, silent() called exit on failure, making all 86+ instances
of '$STD cmd || true' across the codebase silently broken - the || true
never had a chance to execute.

Now silent() returns the exit code, letting callers handle errors:
- $STD cmd || true  -> works correctly (continues on failure)
- $STD cmd          -> set -e + ERR trap catches it -> error_handler()

error_handler() picks up metadata (_SILENT_FAILED_*) from silent() to
show the actual command, line number, and log tail.
This commit is contained in:
MickLesk
2026-04-04 22:42:54 +02:00
parent 9ce2fe9ee0
commit 4e029b86cb
3 changed files with 40 additions and 46 deletions

View File

@@ -236,6 +236,16 @@ error_handler() {
command="${command//\$STD/}"
# If error originated from silent(), use its captured metadata
# This provides the actual command and line number instead of "silent ..."
if [[ -n "${_SILENT_FAILED_RC:-}" ]]; then
exit_code="$_SILENT_FAILED_RC"
command="$_SILENT_FAILED_CMD"
line_number="$_SILENT_FAILED_LINE"
# Clear flags to prevent stale data on subsequent errors
unset _SILENT_FAILED_RC _SILENT_FAILED_CMD _SILENT_FAILED_LINE
fi
if [[ "$exit_code" -eq 0 ]]; then
return 0
fi
@@ -279,8 +289,12 @@ error_handler() {
fi
# Get active log file (BUILD_LOG or INSTALL_LOG)
# Prefer silent()'s logfile when available (contains the actual command output)
local active_log=""
if declare -f get_active_logfile >/dev/null 2>&1; then
if [[ -n "${_SILENT_FAILED_LOG:-}" && -s "${_SILENT_FAILED_LOG}" ]]; then
active_log="$_SILENT_FAILED_LOG"
unset _SILENT_FAILED_LOG
elif declare -f get_active_logfile >/dev/null 2>&1; then
active_log="$(get_active_logfile)"
elif [[ -n "${SILENT_LOGFILE:-}" ]]; then
active_log="$SILENT_LOGFILE"