From d9af9214178177abbddc8d16c74f6c532fdb3c32 Mon Sep 17 00:00:00 2001 From: levasseur Date: Mon, 13 Dec 2021 18:49:03 +0100 Subject: [PATCH] libs: made error message clearer and more consistent --- lib/aaa_errors.sh | 2 +- lib/filefct.sh | 6 +++--- lib/services.sh | 2 +- lib/utils.sh | 5 +++++ lib/version.sh | 6 +++--- lib/zzz_main_fct.sh | 8 ++++---- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/aaa_errors.sh b/lib/aaa_errors.sh index 5ad7880..39ea266 100644 --- a/lib/aaa_errors.sh +++ b/lib/aaa_errors.sh @@ -134,7 +134,7 @@ check_root() return 0 fi if [[ $EUID -ne 0 ]]; then - prnt E "That script must be run with root privileges." + prnt E "check_root: That script must be run with root privileges." die 4 --force fi } diff --git a/lib/filefct.sh b/lib/filefct.sh index 0aa3c35..b7b67ca 100644 --- a/lib/filefct.sh +++ b/lib/filefct.sh @@ -152,7 +152,7 @@ isdirempty() dir=$1 if [[ -f $dir ]]; then - prnt E "isdirempty():The given parameter is not a directory." + prnt E "isdirempty(): The given parameter is not a directory." die 15 fi if [[ ! -d $dir ]]; then @@ -177,7 +177,7 @@ patchfile() local workfile=${dstfile}.work if [[ ! -s $srcfile ]]; then - prnt E "The source file is empty, is not a file or don't exists!" + prnt E "patchfile(): Source file is empty, is not a file or don't exists!" die 10 fi @@ -218,7 +218,7 @@ file_exists() prnt I "Checking $@ files existance..." for f in $@; do if [[ ! -f $(select_file $f) ]]; then - prnt E "The $f file is missing, cannot continue." + prnt E "file_exists(): The $f file is missing, can't continue." die 10 fi done diff --git a/lib/services.sh b/lib/services.sh index a1b10b7..9a0d0cc 100644 --- a/lib/services.sh +++ b/lib/services.sh @@ -15,7 +15,7 @@ exec_serv() { if [[ $# -lt 2 ]]; then - prnt E "exec_serv(): Syntax error!" + prnt E "exec_serv(): Syntax error (parameters: $@)!" exit 11 fi diff --git a/lib/utils.sh b/lib/utils.sh index 8b1cde4..0c0c4cf 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -21,6 +21,11 @@ export -f stdtime # ------------------------------------------------------------------------------ # Check if a function exists, return 0 if so function_exists() { + if [[ $# -ne 1 ]]; then + prnt E "function_exists(): A function name is required!" + die 11 --force + fi + LC_ALL=C type -t $1 | grep function return $? } diff --git a/lib/version.sh b/lib/version.sh index 899aa68..f8f4afd 100644 --- a/lib/version.sh +++ b/lib/version.sh @@ -13,7 +13,7 @@ get_os_version() { if [[ ! -f /etc/os-release ]]; then - prnt E "Your distribution doesn't have the needed os-release file." + prnt E "get_os_version(): Your distribution doesn't have the needed os-release file." die 8 --force fi @@ -26,7 +26,7 @@ get_os_version() source /etc/os-release if [[ -z $ID ]]; then - prnt E "Your /etc/os-release file mises some vital information." + prnt E "get_os_version(): Your /etc/os-release file mises some vital information." die --force 8 fi @@ -50,7 +50,7 @@ export read_os_release set_sys_vars() { if [[ $# -ne 4 ]]; then - prnt E "get_os_version(): incorect number of parameters ($@)." + prnt E "set_sys_vars(): Incorrect number of parameters ($@)." die --force 7 fi diff --git a/lib/zzz_main_fct.sh b/lib/zzz_main_fct.sh index 2153e61..5d11f21 100644 --- a/lib/zzz_main_fct.sh +++ b/lib/zzz_main_fct.sh @@ -16,7 +16,7 @@ read_commandline() { syntax_error() { - prnt E "Error while analysing command line, please check your parameters." + prnt E "Error while analysing command line parameters." die 1 --force } @@ -52,9 +52,9 @@ read_commandline() if [[ -s $STAGE_FILE ]]; then export RESUME=true else - prnt E "The state file doesn't exists or is empty!" + prnt E "The status file doesn't exists or is empty!" prnt E "Without it, resuming is impossible." - die 1 --force + die 17 --force fi ;; "-R"|"--no-root-check") @@ -102,7 +102,7 @@ read_commandline() export NEW_LOGFILE=$opt want_logfile=false else - prnt E "It's impossible to specify several log files." + prnt E "Impossible to specify several log files." die 1 --force fi elif [[ $want_conffile == true ]]; then