Skip to content

Commit

Permalink
use traceAndDie where die does not give enough context
Browse files Browse the repository at this point in the history
  • Loading branch information
robstoll committed Oct 18, 2024
1 parent 8fdfbbe commit d0f90da
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 65 deletions.
10 changes: 5 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ unset CDPATH

function logError() {
local -r msg=$1
shift 1 || die "could not shift by 1"
shift 1 || traceAndDie "could not shift by 1"
# shellcheck disable=SC2059
printf >&2 "\033[0;31mERROR\033[0m: $msg\n" "$@"
}
Expand All @@ -48,14 +48,14 @@ function die() {

function logSuccess() {
local -r msg=$1
shift 1 || die "could not shift by 1"
shift 1 || traceAndDie "could not shift by 1"
# shellcheck disable=SC2059
printf "\033[0;32mSUCCESS\033[0m: $msg\n" "$@"
}

function logInfo() {
local msg=$1
shift || die "could not shift by 1"
shift 1 || traceAndDie "could not shift by 1"
# shellcheck disable=SC2059
printf "\033[0;34mINFO\033[0m: $msg\n" "$@"
}
Expand All @@ -76,7 +76,7 @@ function exitIfCommandDoesNotExist() {

function deleteDirChmod777() {
local -r dir=$1
shift 1 || die "could not shift by 1"
shift 1 || traceAndDie "could not shift by 1"
# e.g files in .git will be write-protected and we don't want sudo for this command
# yet, if it fails, then we ignore the problem and still try to delete the folder
chmod -R 777 "$dir" || true
Expand All @@ -103,7 +103,7 @@ function install() {
local -r tag=$1
local -r installDir=$2
local -r symbolicLink=$3
shift 3 || die "could not shift by 3"
shift 3 || traceAndDie "could not shift by 3"

local -r versionRegex="^(v[0-9]+)\.([0-9]+)\.[0-9]+(-RC[0-9]+)?$"
if ! grep -Eq "$versionRegex" >/dev/null <<<"$tag"; then
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare-next-dev-cycle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sourceOnce "$scriptsDir/before-pr.sh"
sourceOnce "$scriptsDir/update-version-in-non-sh-files.sh"

function prepareNextDevCycle() {
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || die "could not source common-constants.source.sh"
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"

# shellcheck disable=SC2034 # they seem unused but are necessary in order that parseArguments doesn't create global readonly vars
local version projectsRootDir additionalPattern beforePrFn
Expand Down
2 changes: 1 addition & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sourceOnce "$scriptsDir/prepare-next-dev-cycle.sh"
sourceOnce "$scriptsDir/update-version-in-non-sh-files.sh"

function release() {
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || die "could not source common-constants.source.sh"
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"

local version
# shellcheck disable=SC2034 # they seem unused but are necessary in order that parseArguments doesn't create global readonly vars
Expand Down
2 changes: 1 addition & 1 deletion scripts/update-version-in-non-sh-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sourceOnce "$dir_of_tegonal_scripts/releasing/update-version-scripts.sh"
sourceOnce "$dir_of_tegonal_scripts/utility/parse-args.sh"

function updateVersionInNonShFiles() {
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || die "could not source common-constants.source.sh"
source "$dir_of_tegonal_scripts/releasing/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
local version projectsRootDir additionalPattern
parseArguments afterVersionHookParams "" "$GT_VERSION" "$@"

Expand Down
10 changes: 5 additions & 5 deletions src/gt-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function gt_pull() {
local -r currentDir

local pulledTsvLatestVersionPragma pulledTsvHeader
source "$dir_of_gt/common-constants.source.sh" || die "could not source common-constants.source.sh"
source "$dir_of_gt/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
local -r UNSECURE_NO_VERIFY_PATTERN='--unsecure-no-verification'

local remote tag path pullDir chopPath workingDir autoTrust unsecure forceNoVerification
Expand Down Expand Up @@ -145,14 +145,14 @@ function gt_pull() {
exitIfRemoteDirDoesNotExist "$workingDirAbsolute" "$remote"

local publicKeysDir repo gpgDir pulledTsv pullHookFile
source "$dir_of_gt/paths.source.sh" || die "could not source paths.source.sh"
source "$dir_of_gt/paths.source.sh" || traceAndDie "could not source paths.source.sh"

if ! [[ -d $pullDirAbsolute ]]; then
mkdir -p "$pullDirAbsolute" || die "failed to create the pull directory %s" "$pullDirAbsolute"
fi

if ! [[ -f $pulledTsv ]]; then
echo "$pulledTsvLatestVersionPragma"$'\n'"$pulledTsvHeader" >"$pulledTsv" || die "failed to initialise the pulled.tsv file at %s" "$pulledTsv"
echo "$pulledTsvLatestVersionPragma"$'\n'"$pulledTsvHeader" >"$pulledTsv" || die "failed to initialise the pulled.tsv file at \033[0;36m%s\033[0m" "$pulledTsv"
else
exitIfHeaderOfPulledTsvIsWrong "$pulledTsv"
fi
Expand All @@ -162,7 +162,7 @@ function gt_pull() {
local tagToPull="$tag"
# tag was actually omitted, so we use the latest remote tag instead
if [[ $tag == "$fakeTag" ]]; then
tagToPull=$(latestRemoteTagIncludingChecks "$workingDirAbsolute" "$remote") || die "could not determine latest tag, see above"
tagToPull=$(latestRemoteTagIncludingChecks "$workingDirAbsolute" "$remote") || die "could not determine latest tag of remote \033[0;36m%s\033[0m, see above" "$remote"
fi
local -r tagToPull

Expand Down Expand Up @@ -261,7 +261,7 @@ function gt_pull() {
local pullHookAfter="gt_pull_noop"
if [[ -f $pullHookFile ]]; then
# shellcheck disable=SC2310 # we are aware of that || will disable set -e for sourceOnce
sourceOnce "$pullHookFile" || die "could not source %s" "$pullHookFile"
sourceOnce "$pullHookFile" || traceAndDie "could not source %s" "$pullHookFile"
pullHookBefore="gt_pullHook_${remote//-/_}_before"
pullHookAfter="gt_pullHook_${remote//-/_}_after"
fi
Expand Down
10 changes: 5 additions & 5 deletions src/gt-re-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function gt_re_pull() {
startTime=$(date +%s.%3N)

local defaultWorkingDir
source "$dir_of_gt/common-constants.source.sh" || die "could not source common-constants.source.sh"
source "$dir_of_gt/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"

local -r onlyMissingPattern="--only-missing"

Expand Down Expand Up @@ -100,18 +100,18 @@ function gt_re_pull() {
function gt_re_pull_incrementError() {
local -r entryFile=$1
local -r remote=$2
shift 2 || die "could not shift by 2"
shift 2 || traceAndDie "could not shift by 2"
logError "could not pull \033[0;36m%s\033[0m from remote %s" "$entryFile" "$remote"
((++errors))
}

# shellcheck disable=SC2317 # called by name
function gt_re_pull_rePullInternal() {
local -r remote=$1
shift 1 || die "could not shift by 1"
shift 1 || traceAndDie "could not shift by 1"

local repo
source "$dir_of_gt/paths.source.sh" || die "could not source paths.source.sh"
source "$dir_of_gt/paths.source.sh" || traceAndDie "could not source paths.source.sh"

function gt_re_pull_rePullInternal_callback() {
local entryTag entryFile _entryRelativePath entryAbsolutePath
Expand Down Expand Up @@ -140,7 +140,7 @@ function gt_re_pull() {

function gt_re_pull_rePullRemote() {
local -r remote=$1
shift 1 || die "could not shift by 1"
shift 1 || traceAndDie "could not shift by 1"
withCustomOutputInput 5 6 gt_re_pull_rePullInternal "$remote"
}

Expand Down
12 changes: 6 additions & 6 deletions src/gt-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ function gt_remote_cleanupRemoteOnUnexpectedExit() {

local -r remoteDir=$1
local -r currentDir=$2
shift 2 || die "could not shift by 2"
shift 2 || traceAndDie "could not shift by 2"

if ! ((result == 0)) && [[ -d $remoteDir ]]; then
deleteDirChmod777 "$remoteDir"
fi
}

function gt_remote_add() {
source "$dir_of_gt/common-constants.source.sh" || die "could not source common-constants.source.sh"
source "$dir_of_gt/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"

local currentDir
currentDir=$(pwd) || die "could not determine currentDir, maybe it does not exist anymore?"
Expand Down Expand Up @@ -126,7 +126,7 @@ function gt_remote_add() {
mkdir -p "$workingDirAbsolute/remotes" || die "was not able to create directory %s" "$workingDirAbsolute/remotes"

local remoteDir publicKeysDir repo gpgDir pullArgsFile gitconfig
source "$dir_of_gt/paths.source.sh" || die "could not source paths.source.sh"
source "$dir_of_gt/paths.source.sh" || traceAndDie "could not source paths.source.sh"

if [[ -f $remoteDir ]]; then
die "cannot create remote directory, there is a file at this location: %s" "$remoteDir"
Expand Down Expand Up @@ -229,7 +229,7 @@ function gt_remote_list_raw() {

local remotesDir
local -r remote="not really a remote but paths.source.sh requires it, hence we set it here but don't use it afterwards"
source "$dir_of_gt/paths.source.sh" || die "could not source paths.source.sh"
source "$dir_of_gt/paths.source.sh" || traceAndDie "could not source paths.source.sh"

local cutLength
cutLength=$((${#remotesDir} + 2))
Expand All @@ -254,7 +254,7 @@ function gt_remote_list() {
}

function gt_remote_remove() {
source "$dir_of_gt/common-constants.source.sh" || die "could not source common-constants.source.sh"
source "$dir_of_gt/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"

local remote workingDir
# shellcheck disable=SC2034 # is passed by name to parseArguments
Expand Down Expand Up @@ -286,7 +286,7 @@ function gt_remote_remove() {
local -r workingDirAbsolute

local remoteDir pulledTsv pullHookFile
source "$dir_of_gt/paths.source.sh" || die "could not source paths.source.sh"
source "$dir_of_gt/paths.source.sh" || traceAndDie "could not source paths.source.sh"

if [[ -f $remoteDir ]]; then
logError "cannot delete remote \033[0;36m%s\033[0m, looks like it is broken there is a file at this location: %s" "$remote" "$remoteDir"
Expand Down
6 changes: 3 additions & 3 deletions src/gt-reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sourceOnce "$dir_of_tegonal_scripts/utility/parse-args.sh"

function gt_reset() {
local defaultWorkingDir unsecureParamPattern
source "$dir_of_gt/common-constants.source.sh" || die "could not source common-constants.source.sh"
source "$dir_of_gt/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"

local remote workingDir
# shellcheck disable=SC2034 # is passed by name to parseArguments
Expand Down Expand Up @@ -97,7 +97,7 @@ function gt_reset() {
exitIfRepoBrokenAndReInitIfAbsent "$workingDirAbsolute" "$remote"

local publicKeysDir gpgDir repo pullArgsFile
source "$dir_of_gt/paths.source.sh" || die "could not source paths.source.sh"
source "$dir_of_gt/paths.source.sh" || traceAndDie "could not source paths.source.sh"
if [[ -d $publicKeysDir ]]; then
logInfo "Going to re-establish gpg trust in remote \033[0;36m%s\033[0m, removing %s" "$remote" "$publicKeysDir"
deleteDirChmod777 "$publicKeysDir" || die "could not delete the public keys dir of remote \033[0;36m%s\033[0m" "$remote"
Expand Down Expand Up @@ -170,7 +170,7 @@ function gt_reset() {

if [[ -n $remote ]]; then
#shellcheck disable=SC2310 # we know that set -e is disabled for gt_reset_resetRemote due to ||
gt_reset_resetRemote "$remote" || die "could not remove gpg directory for remote %s, see above" "$remote"
gt_reset_resetRemote "$remote" || die "could not remove gpg directory for remote \033[0;36m%s\033[0m, see above" "$remote"
if [[ $gpgOnly != true ]]; then
gt_re_pull -w "$workingDirAbsolute" --only-missing false -r "$remote"
fi
Expand Down
4 changes: 2 additions & 2 deletions src/gt-self-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function gt_self_update() {
printf ", but '%s true' was specified, going to re-install it\n" "$forcePattern"
fi
fi
cd "$currentDir" || die "could not cd back to the current dir"
cd "$currentDir" || die "could not cd back to the current dir %s" "$currentDir"
else
logInfo "looks like you did not install gt via install.sh (%s does not exist)" "$installDir/.git"
if ! askYesOrNo "Do you want to run the following command to replace the current installation with the latest version:\ninstall.sh --directory \"%s\"" "$installDir"; then
Expand All @@ -99,7 +99,7 @@ function gt_self_update() {
local tmpDir
tmpDir=$(mktemp -d -t gt-install-XXXXXXXXXX)
cp -r "$installDir" "$tmpDir/gt"
cd "$tmpDir/gt" || die "could not cd to the tmpDir, see above"
cd "$tmpDir/gt" || die "could not cd to the tmpDir %s, see above" "$tmpDir/gt"
./install.sh --directory "$installDir"
}

Expand Down
8 changes: 4 additions & 4 deletions src/gt-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function gt_update() {
startTime=$(date +%s.%3N)

local defaultWorkingDir
source "$dir_of_gt/common-constants.source.sh" || die "could not source common-constants.source.sh"
source "$dir_of_gt/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"

local remote workingDir autoTrust tag
# shellcheck disable=SC2034 # is passed by name to parseFnArgs
Expand Down Expand Up @@ -98,15 +98,15 @@ function gt_update() {
function gt_update_incrementError() {
local -r entryFile=$1
local -r remote=$2
shift 2 || die "could not shift by 2"
shift 2 || traceAndDie "could not shift by 2"
logError "could not pull \033[0;36m%s\033[0m from remote %s" "$entryFile" "$remote"
((++errors))
}

# shellcheck disable=SC2317 # called by name
function gt_update_rePullInternal() {
local -r remote=$1
shift 1 || die "could not shift by 1"
shift 1 || traceAndDie "could not shift by 1"

local tagToPull
if [[ -n $tag ]]; then
Expand Down Expand Up @@ -135,7 +135,7 @@ function gt_update() {

function gt_update_rePullRemote() {
local -r remote=$1
shift 1 || die "could not shift by 1"
shift 1 || traceAndDie "could not shift by 1"

exitIfRemoteDirDoesNotExist "$workingDir" "$remote"

Expand Down
2 changes: 1 addition & 1 deletion src/gt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ sourceOnce "$dir_of_tegonal_scripts/utility/parse-commands.sh"

function gt_source() {
local -r command=$1
shift || die "could not shift by 1"
shift 1 || traceAndDie "could not shift by 1"
sourceOnce "$dir_of_gt/gt-$command.sh"
}

Expand Down
4 changes: 2 additions & 2 deletions src/install/include-install-doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function includeInstallDoc() {
# using unconventional naming in order to avoid name clashes with the variables we will initialise further below
local -r installDocSh=$1
local -rn includeInstallDoc_files=$2
shift 2 || die "could not shift by 2"
shift 2 || traceAndDie "could not shift by 2"

if ! [[ -f "$installDocSh" ]]; then
returnDying "%s does not exist" "$installDocSh"
Expand Down Expand Up @@ -98,7 +98,7 @@ function includeInstallDoc() {
perl -0777 -i \
-pe "s@(\n\s+# see install.doc.sh.*\n)[^#]+(# end install.doc.sh\n)@\${1}$content\n$indent\${2}@g" \
"$file" || return $?
done || die "could not replace the install instructions"
done || traceAndDie "could not replace the install instructions"
}

${__SOURCED__:+return}
Expand Down
12 changes: 6 additions & 6 deletions src/pulled-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ function pulledTsvEntry() {

function migratePulledTsvFormat() {
local pulledTsvLatestVersionPragma
source "$dir_of_gt/common-constants.source.sh" || die "could not source common-constants.source.sh"
source "$dir_of_gt/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"
local -r pulledTsv=$1
local -r fromVersion=$2
local -r toVersion=$3
shift 3 || die "could not shift by 2"
shift 3 || traceAndDie "could not shift by 2"

if [[ $fromVersion == "unspecified" ]]; then
# pulled.tsv without version pragma, convert to current
Expand All @@ -60,10 +60,10 @@ function migratePulledTsvFormat() {

function exitIfHeaderOfPulledTsvIsWrong() {
local -r pulledTsv=$1
shift 1 || die "could not shift by 1"
shift 1 || traceAndDie "could not shift by 1"

local pulledTsvLatestVersion pulledTsvLatestVersionPragma pulledTsvHeader
source "$dir_of_gt/common-constants.source.sh" || die "could not source common-constants.source.sh"
source "$dir_of_gt/common-constants.source.sh" || traceAndDie "could not source common-constants.source.sh"

local currentVersionPragma currentHeader
currentVersionPragma="$(head -n 1 "$pulledTsv")" || die "could not read the current pulled.tsv at %s" "$pulledTsv"
Expand Down Expand Up @@ -100,7 +100,7 @@ function setEntryVariables() {
function grepPulledEntryByFile() {
local -r pulledTsv=$1
local -r file=$2
shift 2 || die "could not shift by 2"
shift 2 || traceAndDie "could not shift by 2"
grep -E "^[^\t]+ $file" "$@" "$pulledTsv"
}

Expand All @@ -124,7 +124,7 @@ function readPulledTsv() {
exitIfArgIsNotFunction "$readPulledTsv_callback" 3

local pulledTsv
source "$dir_of_gt/paths.source.sh" || die "could not source paths.source.sh"
source "$dir_of_gt/paths.source.sh" || traceAndDie "could not source paths.source.sh"
if ! [[ -f $pulledTsv ]]; then
logWarning "Looks like remote \033[0;36m%s\033[0m is broken or no file has been fetched so far, there is no pulled.tsv, skipping it" "$remote"
return 0
Expand Down
Loading

0 comments on commit d0f90da

Please sign in to comment.