Skip to content

Commit

Permalink
lib/utils: Add new functions for error handling
Browse files Browse the repository at this point in the history
Co-authored-by: Koichi Murase <[email protected]>
  • Loading branch information
Kreyren and akinomyoga committed Oct 15, 2023
1 parent 07d9382 commit 29bcd14
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,37 @@ _omb_term_color_initialize
#
# Headers and Logging
#
function _omb_log_header { printf "\n${_omb_term_bold}${_omb_term_violet}========== %s ==========${_omb_term_reset}\n" "$@"; }
function _omb_log_arrow { printf "➜ %s\n" "$@"; }
function _omb_log_success { printf "${_omb_term_green}✔ %s${_omb_term_reset}\n" "$@"; }
function _omb_log_error { printf "${_omb_term_brown}✖ %s${_omb_term_reset}\n" "$@"; }
function _omb_log_warning { printf "${_omb_term_olive}➜ %s${_omb_term_reset}\n" "$@"; }
function _omb_log_underline { printf "${_omb_term_underline}${_omb_term_bold}%s${_omb_term_reset}\n" "$@"; }
function _omb_log_bold { printf "${_omb_term_bold}%s${_omb_term_reset}\n" "$@"; }
function _omb_log_note { printf "${_omb_term_underline}${_omb_term_bold}${_omb_term_navy}Note:${_omb_term_reset} ${_omb_term_olive}%s${_omb_term_reset}\n" "$@"; }
# Note: Define logging functions only when there are no existing
# definitions so that the end user can customize the error handling.
_omb_util_command_exists _omb_log_header ||
function _omb_log_header { printf "\n${_omb_term_bold}${_omb_term_violet}========== %s ==========${_omb_term_reset}\n" "$@"; }
_omb_util_command_exists _omb_log_arrow ||
function _omb_log_arrow { printf "➜ %s\n" "$@"; }
_omb_util_command_exists _omb_log_success ||
function _omb_log_success { printf "${_omb_term_green}✔ %s${_omb_term_reset}\n" "$@"; }
_omb_util_command_exists _omb_log_error ||
function _omb_log_error { printf "${_omb_term_brown}✖ %s${_omb_term_reset}\n" "$@"; }
_omb_util_command_exists _omb_log_warning ||
function _omb_log_warning { printf "${_omb_term_olive}➜ %s${_omb_term_reset}\n" "$@"; }
_omb_util_command_exists _omb_log_underline ||
function _omb_log_underline { printf "${_omb_term_underline}${_omb_term_bold}%s${_omb_term_reset}\n" "$@"; }
_omb_util_command_exists _omb_log_bold ||
function _omb_log_bold { printf "${_omb_term_bold}%s${_omb_term_reset}\n" "$@"; }
_omb_util_command_exists _omb_log_note ||
function _omb_log_note { printf "${_omb_term_underline}${_omb_term_bold}${_omb_term_navy}Note:${_omb_term_reset} ${_omb_term_olive}%s${_omb_term_reset}\n" "$@"; }
_omb_util_command_exists _omb_log_info ||
function _omb_log_info { printf "INFO: %s\n" "$1"; }
_omb_util_command_exists _omb_log_die ||
function _omb_log_die {
local status=$1
case $status in
1) printf 'FATAL: %s\n' "$2"
exit "$status" ;;
*) printf 'FATAL: Syntax error%s\n%s\n' "${FUNCNAME:+ in $FUNCNAME}" "$2"
((status)) && printf 'FATAL: %s\n' "$status"
return "$status" ;;
esac
}

#
# USAGE FOR SEEKING CONFIRMATION
Expand Down

0 comments on commit 29bcd14

Please sign in to comment.