Skip to content

Commit

Permalink
Merge pull request #13 from env0/fix-err-logs
Browse files Browse the repository at this point in the history
Fix logs - make the visable in our app
  • Loading branch information
razbensimon authored Jul 6, 2023
2 parents a94f168 + 872166c commit aafd4f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions libexec/helpers
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

function error_log() {
echo -e "tgenv: $(basename ${0}): \033[0;31m[ERROR] ${1}\033[0;39m" >&2
}

function error_and_die() {
echo -e "tgenv: $(basename ${0}): \033[0;31m[ERROR] ${1}\033[0;39m" >&2
exit 1
Expand Down
10 changes: 7 additions & 3 deletions libexec/retry
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

info_log() {
echo -e "\033[0;32m[INFO] ${1}\033[0;39m" >&2
}

retry() {
# Default values
local tries=3
Expand Down Expand Up @@ -56,19 +60,19 @@ retry() {
if [[ $exit_code -eq 0 ]]; then
return 0
elif [[ -n $stop_on_exit_code && $exit_code -eq $stop_on_exit_code ]]; then
echo "Exit code ($stop_on_exit_code) matching to condition. Won't retry, exiting."
info_log "Exit code ($stop_on_exit_code) matching to condition. Won't retry, exiting."
return 1
fi

counter=$((counter + 1))

if [[ $counter -lt $tries ]]; then
echo "Attempt $counter failed. Retrying after $sleep_interval seconds..."
info_log "Attempt $counter failed. Retrying after $sleep_interval seconds..."
sleep "$sleep_interval"
fi
done

echo "Command failed after $tries attempts."
info_log "Command failed after $tries attempts."
return 1
}

Expand Down
4 changes: 2 additions & 2 deletions libexec/tgenv-install
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ function install_tg_version() {

local result_code
if [[ $http_code =~ ^4 ]]; then
echo "Got $http_code http code, TG version is invalid"
error_log "Got $http_code http code, TG version is invalid"
result_code=2 # do not retry
elif [[ $http_code =~ ^5 ]]; then
echo "Got $http_code http code"
error_log "Got $http_code http code"
result_code=1 # retry
elif [[ $curl_exit_code -ne 0 ]]; then
result_code=1 # retry
Expand Down

0 comments on commit aafd4f2

Please sign in to comment.