Update core.func
This commit is contained in:
parent
f6560c7362
commit
62e975485f
@ -90,34 +90,16 @@ _tool_error_hint() {
|
||||
}
|
||||
|
||||
on_error() {
|
||||
local exit_code="$?"
|
||||
local lineno="${BASH_LINENO[0]:-unknown}"
|
||||
local code="$?"
|
||||
local line="${BASH_LINENO[0]:-unknown}"
|
||||
local cmd="${BASH_COMMAND:-unknown}"
|
||||
|
||||
# Signalcode unterdrücken, falls INT/TERM kommt
|
||||
[[ "$code" == "130" || "$code" == "143" ]] && return
|
||||
|
||||
_stop_spinner_on_error
|
||||
echo >&2
|
||||
|
||||
case "$exit_code" in
|
||||
1) msg_error "General error at line $lineno: $cmd" ;;
|
||||
2) msg_error "Shell misuse at line $lineno: $cmd" ;;
|
||||
126) msg_error "Command not executable at line $lineno: $cmd" ;;
|
||||
127) msg_error "Command not found at line $lineno: $cmd" ;;
|
||||
128) msg_error "Invalid exit argument at line $lineno: $cmd" ;;
|
||||
130) msg_error "Aborted by user (SIGINT)" ;;
|
||||
143) msg_error "Terminated by SIGTERM" ;;
|
||||
*) msg_error "Script failed at line $lineno with exit code $exit_code: $cmd" ;;
|
||||
esac
|
||||
|
||||
local tool="${cmd%% *}"
|
||||
local hint
|
||||
hint=$(_tool_error_hint "$tool" "$exit_code")
|
||||
[[ -n "$hint" ]] && msg_error "$hint"
|
||||
|
||||
# Optional API oder Logging
|
||||
# post_update_to_api "failed" "Error at line $lineno: $cmd (code $exit_code)"
|
||||
# echo "$(date -Iseconds) [ERR] $cmd (code $exit_code)" >> /var/log/proxmoxved_error.log
|
||||
|
||||
exit "$exit_code"
|
||||
msg_error "Script failed at line $line with exit code $code: $cmd"
|
||||
exit "$code"
|
||||
}
|
||||
|
||||
on_exit() {
|
||||
@ -142,6 +124,7 @@ catch_errors() {
|
||||
trap 'on_exit' EXIT
|
||||
trap 'on_interrupt' INT
|
||||
trap 'on_terminate' TERM
|
||||
|
||||
set -Eeuo pipefail
|
||||
shopt -s inherit_errexit
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user