Skip to content

Commit

Permalink
use traceAndDie instead of die where error msg is not enough context
Browse files Browse the repository at this point in the history
  • Loading branch information
robstoll committed Oct 17, 2024
1 parent 33df7cf commit c0d0e1e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/utility/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function exitIfArgIsNotArrayOrIsEmpty() {
local -r argNumberOrName=$2
shift 2 || traceAndDie "could not shift by 2"
if [[ ${#exitIfArgIsNotArrayOrIsEmpty_arr[@]} -lt 1 ]]; then
die "the passed argument \033[0;36m%s\033[0m is an empty array" "${!checkArgIsArray_arr}"
traceAndDie "the passed argument \033[0;36m%s\033[0m is an empty array" "${!checkArgIsArray_arr}"
fi
}

Expand Down Expand Up @@ -156,7 +156,7 @@ function checkArgIsArrayWithTuples() {
fi

local arrayDefinition
arrayDefinition=$(recursiveDeclareP checkArgIsArrayWithTuples_paramArr) || die "could not get array definition of %s" "${!checkArgIsArrayWithTuples_paramArr}"
arrayDefinition=$(recursiveDeclareP checkArgIsArrayWithTuples_paramArr) || traceAndDie "could not get array definition of %s" "${!checkArgIsArrayWithTuples_paramArr}"
reg='declare -a.*'
if ! [[ "$arrayDefinition" =~ $reg ]]; then
logError "the passed array \033[0;36m%s\033[0m is broken" "${!checkArgIsArrayWithTuples_paramArr}"
Expand Down Expand Up @@ -295,7 +295,7 @@ function exitIfCommandDoesNotExist() {
function exitIfVarsNotAlreadySetBySource() {
for varName in "$@"; do
if ! [[ -v "$varName" ]] || [[ -z ${!varName} ]]; then
die "looks like \$%s was not defined by %s where this file (%s) was sourced" "$varName" "${BASH_SOURCE[2]:-${BASH_SOURCE[1]}}" "${BASH_SOURCE[0]}"
traceAndDie "looks like \$%s was not defined by %s where this file (%s) was sourced" "$varName" "${BASH_SOURCE[2]:-${BASH_SOURCE[1]}}" "${BASH_SOURCE[0]}"
fi
done
}
Expand Down
2 changes: 1 addition & 1 deletion src/utility/git-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function latestRemoteTag() {
local -r tagFilter=${2:-".*"}
local tag
#shellcheck disable=SC2310 # we are aware of that || will disable set -e for remoteTagsSorted
tag=$(remoteTagsSorted "$remote" | grep -E "$tagFilter" | tail -n 1) || die "could not get remote tags sorted, see above"
tag=$(remoteTagsSorted "$remote" | grep -E "$tagFilter" | tail -n 1) || die "could not get remote tags sorted for remote %s, see above" "$remote"
if [[ -z $tag ]]; then
die "looks like remote \033[0;36m%s\033[0m does not have a tag yet." "$remote"
fi
Expand Down
4 changes: 2 additions & 2 deletions src/utility/io.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ function withCustomOutputInput() {

local tmpFile
tmpFile=$(mktemp /tmp/tegonal-scripts-io.XXXXXXXXX)
eval "exec ${outputNr}>\"$tmpFile\"" || die "could not create output file descriptor %s" "$outputNr"
eval "exec ${inputNr}<\"$tmpFile\"" || die "could not create input file descriptor %s" "$inputNr"
eval "exec ${outputNr}>\"$tmpFile\"" || traceAndDie "could not create output file descriptor %s" "$outputNr"
eval "exec ${inputNr}<\"$tmpFile\"" || traceAndDie "could not create input file descriptor %s" "$inputNr"
# don't fail if we cannot delete the tmp file, if this should happened, then the system should clean-up the file when the process ends
rm "$tmpFile" || true

Expand Down
4 changes: 2 additions & 2 deletions src/utility/parse-args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function parseArgumentsInternal {
shift 4 || traceAndDie "could not shift by 4"

if ! [[ "$parseArguments_unknownBehaviour" =~ ^(ignore|error)$ ]]; then
die "unknownBehaviour needs to be one of 'error' or 'ignore' got \033[0;36m%s\033[0m" "$parseArguments_unknownBehaviour"
traceAndDie "unknownBehaviour needs to be one of 'error' or 'ignore' got \033[0;36m%s\033[0m" "$parseArguments_unknownBehaviour"
fi

parse_args_exitIfParameterDefinitionIsNotTriple parseArguments_paramArr
Expand Down Expand Up @@ -178,7 +178,7 @@ function parseArgumentsInternal {
exit 9
fi
# that's where the black magic happens, we are assigning to global (not local to this function) variables here
printf -v "$parseArguments_paramName" "%s" "$2" || die "could not assign value to $parseArguments_paramName"
printf -v "$parseArguments_paramName" "%s" "$2" || traceAndDie "could not assign value to $parseArguments_paramName"
parseArguments_expectedName=1
((++parseArguments_numOfArgumentsParsed))
shift 1 || traceAndDie "could not shift by 1"
Expand Down
4 changes: 2 additions & 2 deletions src/utility/parse-fn-args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ function parseFnArgs() {
for ((parseFnArgs_i = 0; parseFnArgs_i < parseFnArgs_minExpected; ++parseFnArgs_i)); do
local parseFnArgs_name=${parseFnArgs_paramArr1[parseFnArgs_i]}
# assign arguments to specified variables
printf -v "$parseFnArgs_name" "%s" "$1" || die "could not assign value to $parseFnArgs_name"
printf -v "$parseFnArgs_name" "%s" "$1" || traceAndDie "could not assign value to $parseFnArgs_name"
local -r "$parseFnArgs_name"
shift 1 || traceAndDie "could not shift by 1"
done

# assign rest to varargs if used
if [[ $parseFnArgs_withVarArgs == true ]]; then
# shellcheck disable=SC2034 # varargs is defined in outer scope and will be used there, thus ok
varargs=("$@") || die "could not assign the rest of arguments to varargs"
varargs=("$@") || traceAndDie "could not assign the rest of arguments to varargs"
fi
}

0 comments on commit c0d0e1e

Please sign in to comment.