libs: made error message clearer and more consistent

This commit is contained in:
levasseur
2021-12-13 18:49:03 +01:00
parent bbd35ee3c6
commit d9af921417
6 changed files with 17 additions and 12 deletions

View File

@@ -134,7 +134,7 @@ check_root()
return 0 return 0
fi fi
if [[ $EUID -ne 0 ]]; then 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 die 4 --force
fi fi
} }

View File

@@ -152,7 +152,7 @@ isdirempty()
dir=$1 dir=$1
if [[ -f $dir ]]; then 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 die 15
fi fi
if [[ ! -d $dir ]]; then if [[ ! -d $dir ]]; then
@@ -177,7 +177,7 @@ patchfile()
local workfile=${dstfile}.work local workfile=${dstfile}.work
if [[ ! -s $srcfile ]]; then 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 die 10
fi fi
@@ -218,7 +218,7 @@ file_exists()
prnt I "Checking $@ files existance..." prnt I "Checking $@ files existance..."
for f in $@; do for f in $@; do
if [[ ! -f $(select_file $f) ]]; then 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 die 10
fi fi
done done

View File

@@ -15,7 +15,7 @@
exec_serv() exec_serv()
{ {
if [[ $# -lt 2 ]]; then if [[ $# -lt 2 ]]; then
prnt E "exec_serv(): Syntax error!" prnt E "exec_serv(): Syntax error (parameters: $@)!"
exit 11 exit 11
fi fi

View File

@@ -21,6 +21,11 @@ export -f stdtime
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Check if a function exists, return 0 if so # Check if a function exists, return 0 if so
function_exists() { 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 LC_ALL=C type -t $1 | grep function
return $? return $?
} }

View File

@@ -13,7 +13,7 @@
get_os_version() get_os_version()
{ {
if [[ ! -f /etc/os-release ]]; then 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 die 8 --force
fi fi
@@ -26,7 +26,7 @@ get_os_version()
source /etc/os-release source /etc/os-release
if [[ -z $ID ]]; then 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 die --force 8
fi fi
@@ -50,7 +50,7 @@ export read_os_release
set_sys_vars() set_sys_vars()
{ {
if [[ $# -ne 4 ]]; then 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 die --force 7
fi fi

View File

@@ -16,7 +16,7 @@ read_commandline()
{ {
syntax_error() syntax_error()
{ {
prnt E "Error while analysing command line, please check your parameters." prnt E "Error while analysing command line parameters."
die 1 --force die 1 --force
} }
@@ -52,9 +52,9 @@ read_commandline()
if [[ -s $STAGE_FILE ]]; then if [[ -s $STAGE_FILE ]]; then
export RESUME=true export RESUME=true
else 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." prnt E "Without it, resuming is impossible."
die 1 --force die 17 --force
fi fi
;; ;;
"-R"|"--no-root-check") "-R"|"--no-root-check")
@@ -102,7 +102,7 @@ read_commandline()
export NEW_LOGFILE=$opt export NEW_LOGFILE=$opt
want_logfile=false want_logfile=false
else else
prnt E "It's impossible to specify several log files." prnt E "Impossible to specify several log files."
die 1 --force die 1 --force
fi fi
elif [[ $want_conffile == true ]]; then elif [[ $want_conffile == true ]]; then