Update core.func
This commit is contained in:
parent
773ae42241
commit
ca023e077e
@ -193,7 +193,7 @@ SILENT_LOGFILE="/tmp/silent.$$.log"
|
|||||||
|
|
||||||
silent() {
|
silent() {
|
||||||
local cmd="$*"
|
local cmd="$*"
|
||||||
local caller_line="${BASH_LINENO[0]:-unknown}" # Capture the line where silent was called
|
local caller_line="${BASH_LINENO[0]:-unknown}"
|
||||||
|
|
||||||
set +Eeuo pipefail
|
set +Eeuo pipefail
|
||||||
"$@" >>"$SILENT_LOGFILE" 2>&1
|
"$@" >>"$SILENT_LOGFILE" 2>&1
|
||||||
@ -201,12 +201,20 @@ silent() {
|
|||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
if [[ $rc -ne 0 ]]; then
|
if [[ $rc -ne 0 ]]; then
|
||||||
# Call error_handler with proper line number context
|
local explanation
|
||||||
BASH_LINENO[0]=$caller_line # Set the line number for error_handler
|
explanation="$(explain_exit_code "$rc")"
|
||||||
error_handler "$rc" "$cmd"
|
|
||||||
fi
|
|
||||||
|
|
||||||
return $rc
|
printf "\e[?25h"
|
||||||
|
echo -e "\n${RD}[ERROR]${CL} in line ${RD}${caller_line}${CL}: exit code ${RD}${rc}${CL} (${explanation}): while executing command ${YWB}${cmd}${CL}\n"
|
||||||
|
|
||||||
|
if [[ -s "$SILENT_LOGFILE" ]]; then
|
||||||
|
echo "--- Last 20 lines of silent log ($SILENT_LOGFILE) ---"
|
||||||
|
tail -n 20 "$SILENT_LOGFILE"
|
||||||
|
echo "---------------------------------------------------"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit "$rc"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if the shell is using bash
|
# Check if the shell is using bash
|
||||||
|
Loading…
x
Reference in New Issue
Block a user