From 313a5be0689247680962a8d8f52da8d15e80fc83 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Mon, 28 Jul 2025 09:19:41 +0200 Subject: [PATCH] better error handling --- misc/create_lxc.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/misc/create_lxc.sh b/misc/create_lxc.sh index 7cc7b702..6e966872 100644 --- a/misc/create_lxc.sh +++ b/misc/create_lxc.sh @@ -31,10 +31,15 @@ function on_exit() { exit "$exit_code" } -function error_handler() { +error_handler() { local exit_code="$?" local line_number="$1" local command="$2" + + if [[ "${USER_EXITED:-false}" == "true" ]]; then + exit "$exit_code" + fi + printf "\e[?25h" echo -e "\n${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}\n" exit "$exit_code" @@ -45,12 +50,14 @@ function on_interrupt() { exit 130 } -function on_terminate() { +on_terminate() { + [[ "${USER_EXITED:-false}" == "true" ]] && exit 0 echo -e "\n${RD}Terminated by signal (SIGTERM)${CL}" exit 143 } exit_script() { + USER_EXITED=true clear printf "\e[?25h" echo -e "\n${CROSS}${RD}User exited script${CL}\n"