From 329cf659e475f58c2be03e802f5ec9163ab8ed42 Mon Sep 17 00:00:00 2001 From: RedLeaderOne Date: Thu, 8 Aug 2024 15:07:49 -0400 Subject: [PATCH] fix(error-handling): Improve error messages in library sourcing script - Enhance error handling by adding descriptive error messages to `pushd`, `cd`, and `source` commands. - Ensure script provides detailed feedback when failing to navigate directories or sourcing files. Issue NMO-581 --- import_norlab_shell_script_tools_lib.bash | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/import_norlab_shell_script_tools_lib.bash b/import_norlab_shell_script_tools_lib.bash index e79c7e3..5b403ab 100644 --- a/import_norlab_shell_script_tools_lib.bash +++ b/import_norlab_shell_script_tools_lib.bash @@ -21,7 +21,7 @@ MSG_ERROR_FORMAT="\033[1;31m" MSG_END_FORMAT="\033[0m" function n2st::source_lib(){ - pushd "$(pwd)" >/dev/null || exit 1 + pushd "$(pwd)" >/dev/null || { echo "pushd error" 1>&2 && exit 1;} # Note: can handle both sourcing cases # i.e. from within a script or from an interactive terminal session @@ -29,15 +29,15 @@ function n2st::source_lib(){ _REPO_ROOT="$(dirname "${_PATH_TO_SCRIPT}")" # ....Load environment variables from file....................................................... - cd "${_REPO_ROOT}" || exit 1 + cd "${_REPO_ROOT}" || { echo "${_REPO_ROOT} unreachable" 1>&2 && exit 1;} set -o allexport source .env.n2st set +o allexport # ....Begin...................................................................................... - cd "${N2ST_PATH:?'[ERROR] env var not set!'}/src/function_library" || exit 1 + cd "${N2ST_PATH:?'[ERROR] env var not set!'}/src/function_library" || { echo "${N2ST_PATH} unreachable" 1>&2 && exit 1;} for each_file in "$(pwd)"/*.bash ; do - source "${each_file}" + source "${each_file}" || { echo "${each_file} unexpected error" 1>&2 && exit 1;} done # (NICE TO HAVE) ToDo: append lib to PATH (ref task NMO-414) @@ -48,7 +48,7 @@ function n2st::source_lib(){ export N2ST_VERSION # ....Teardown................................................................................... - popd >/dev/null || exit 1 + popd >/dev/null || { echo "popd error" 1>&2 && exit 1;} } # ::::Main:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::