Skip to content

Commit

Permalink
Add error messages when streaming or downloading a file fails (#79)
Browse files Browse the repository at this point in the history
* Add error messages when streaming or downloading a file fails

* Exclude home URL test

* Update stream and download functions to work properly with errexit
  • Loading branch information
mcafaro authored Nov 7, 2024
1 parent 511c96f commit 4a323cd
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ workflows:
- orb-tools/pack:
filters: *filters
- orb-tools/review:
exclude: RC005
exclude: RC005,RC007
filters: *filters
- shellcheck/check:
exclude: SC2148,SC2038,SC2086,SC2002,SC2016
Expand Down
24 changes: 20 additions & 4 deletions src/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,43 @@ sudoIfAvailable() {

stream() {
local url="$1"
local status=0

if command -v wget >/dev/null 2>&1; then
wget --retry-connrefused --waitretry=5 -qO- "$url"
wget --retry-connrefused --waitretry=5 -qO- "$url" || status=$?
elif command -v curl >/dev/null 2>&1; then
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url"
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url" || status=$?
else
echo "Could not find wget or curl command" >&2
return 1
fi

if [ $status -ne 0 ]; then
echo "Error streaming file from $url" >&2
fi

return $status
}

download() {
local url="$1"
local filename="$2"
local status=0

if command -v wget >/dev/null 2>&1; then
wget --retry-connrefused --waitretry=5 -qO "$filename" "$url" 2>&1
wget --retry-connrefused --waitretry=5 -qO "$filename" "$url" 2>&1 || status=$?
elif command -v curl >/dev/null 2>&1; then
curl --retry 5 --retry-all-errors --retry-delay 5 -sSLo "$filename" "$url"
curl --retry 5 --retry-all-errors --retry-delay 5 -sSLo "$filename" "$url" || status=$?
else
echo "Could not find wget or curl command" >&2
return 1
fi

if [ $status -ne 0 ]; then
echo "Error downloading file from $url to $filename" >&2
fi

return $status
}

os=$(uname)
Expand Down
12 changes: 10 additions & 2 deletions src/scripts/run-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ sudoIfAvailable() {

stream() {
local url="$1"
local status=0

if command -v wget >/dev/null 2>&1; then
wget --retry-connrefused --waitretry=5 -qO- "$url"
wget --retry-connrefused --waitretry=5 -qO- "$url" || status=$?
elif command -v curl >/dev/null 2>&1; then
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url"
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url" || status=$?
else
echo "Could not find wget or curl command" >&2
return 1
fi

if [ $status -ne 0 ]; then
echo "Error streaming file from $url" >&2
fi

return $status
}

tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'run-build')
Expand Down
12 changes: 10 additions & 2 deletions src/scripts/run-command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ sudoIfAvailable() {

stream() {
local url="$1"
local status=0

if command -v wget >/dev/null 2>&1; then
wget --retry-connrefused --waitretry=5 -qO- "$url"
wget --retry-connrefused --waitretry=5 -qO- "$url" || status=$?
elif command -v curl >/dev/null 2>&1; then
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url"
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url" || status=$?
else
echo "Could not find wget or curl command" >&2
return 1
fi

if [ $status -ne 0 ]; then
echo "Error streaming file from $url" >&2
fi

return $status
}

tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'run-command')
Expand Down
24 changes: 20 additions & 4 deletions src/scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,43 @@ sudoIfAvailable() {

stream() {
local url="$1"
local status=0

if command -v wget >/dev/null 2>&1; then
wget --retry-connrefused --waitretry=5 -qO- "$url"
wget --retry-connrefused --waitretry=5 -qO- "$url" || status=$?
elif command -v curl >/dev/null 2>&1; then
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url"
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url" || status=$?
else
echo "Could not find wget or curl command" >&2
return 1
fi

if [ $status -ne 0 ]; then
echo "Error streaming file from $url" >&2
fi

return $status
}

download() {
local url="$1"
local filename="$2"
local status=0

if command -v wget >/dev/null 2>&1; then
wget --retry-connrefused --waitretry=5 -qO "$filename" "$url" 2>&1
wget --retry-connrefused --waitretry=5 -qO "$filename" "$url" 2>&1 || status=$?
elif command -v curl >/dev/null 2>&1; then
curl --retry 5 --retry-all-errors --retry-delay 5 -sSLo "$filename" "$url"
curl --retry 5 --retry-all-errors --retry-delay 5 -sSLo "$filename" "$url" || status=$?
else
echo "Could not find wget or curl command" >&2
return 1
fi

if [ $status -ne 0 ]; then
echo "Error downloading file from $url to $filename" >&2
fi

return $status
}

tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'run-tests')
Expand Down

0 comments on commit 4a323cd

Please sign in to comment.