mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-19 21:55:10 +00:00
fix(common): validate log level after error function (#133)
This commit is contained in:
@@ -21,11 +21,6 @@ declare -A LOG_LEVELS=(
|
|||||||
[WARN]=2
|
[WARN]=2
|
||||||
[ERROR]=3
|
[ERROR]=3
|
||||||
)
|
)
|
||||||
LOG_LEVEL="${LOG_LEVEL:-INFO}"
|
|
||||||
if [[ -z "${LOG_LEVELS[$LOG_LEVEL]+_}" ]]; then
|
|
||||||
lib::error "Invalid LOG_LEVEL: $LOG_LEVEL"
|
|
||||||
exit "${ERROR_CODES[INVALID_ARGUMENT]}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Simple logging function
|
# Simple logging function
|
||||||
#
|
#
|
||||||
@@ -78,6 +73,12 @@ lib::error()
|
|||||||
printf '[%s] ERROR: %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*" >&2
|
printf '[%s] ERROR: %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_LEVEL="${LOG_LEVEL:-INFO}"
|
||||||
|
if [[ -z "${LOG_LEVELS[$LOG_LEVEL]+_}" ]]; then
|
||||||
|
lib::error "Invalid LOG_LEVEL: $LOG_LEVEL"
|
||||||
|
exit "${ERROR_CODES[INVALID_ARGUMENT]}"
|
||||||
|
fi
|
||||||
|
|
||||||
# Handle an error by logging an error message to the console
|
# Handle an error by logging an error message to the console
|
||||||
# and exiting with an error code based on the error type.
|
# and exiting with an error code based on the error type.
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user