Skip to content

Commit 4a323cd

Browse files
authored
Add error messages when streaming or downloading a file fails (#79)
* Add error messages when streaming or downloading a file fails * Exclude home URL test * Update stream and download functions to work properly with errexit
1 parent 511c96f commit 4a323cd

File tree

5 files changed

+61
-13
lines changed

5 files changed

+61
-13
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ workflows:
1717
- orb-tools/pack:
1818
filters: *filters
1919
- orb-tools/review:
20-
exclude: RC005
20+
exclude: RC005,RC007
2121
filters: *filters
2222
- shellcheck/check:
2323
exclude: SC2148,SC2038,SC2086,SC2002,SC2016

src/scripts/install.sh

+20-4
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,43 @@ sudoIfAvailable() {
1919

2020
stream() {
2121
local url="$1"
22+
local status=0
23+
2224
if command -v wget >/dev/null 2>&1; then
23-
wget --retry-connrefused --waitretry=5 -qO- "$url"
25+
wget --retry-connrefused --waitretry=5 -qO- "$url" || status=$?
2426
elif command -v curl >/dev/null 2>&1; then
25-
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url"
27+
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url" || status=$?
2628
else
2729
echo "Could not find wget or curl command" >&2
2830
return 1
2931
fi
32+
33+
if [ $status -ne 0 ]; then
34+
echo "Error streaming file from $url" >&2
35+
fi
36+
37+
return $status
3038
}
3139

3240
download() {
3341
local url="$1"
3442
local filename="$2"
43+
local status=0
44+
3545
if command -v wget >/dev/null 2>&1; then
36-
wget --retry-connrefused --waitretry=5 -qO "$filename" "$url" 2>&1
46+
wget --retry-connrefused --waitretry=5 -qO "$filename" "$url" 2>&1 || status=$?
3747
elif command -v curl >/dev/null 2>&1; then
38-
curl --retry 5 --retry-all-errors --retry-delay 5 -sSLo "$filename" "$url"
48+
curl --retry 5 --retry-all-errors --retry-delay 5 -sSLo "$filename" "$url" || status=$?
3949
else
4050
echo "Could not find wget or curl command" >&2
4151
return 1
4252
fi
53+
54+
if [ $status -ne 0 ]; then
55+
echo "Error downloading file from $url to $filename" >&2
56+
fi
57+
58+
return $status
4359
}
4460

4561
os=$(uname)

src/scripts/run-build.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@ sudoIfAvailable() {
1919

2020
stream() {
2121
local url="$1"
22+
local status=0
23+
2224
if command -v wget >/dev/null 2>&1; then
23-
wget --retry-connrefused --waitretry=5 -qO- "$url"
25+
wget --retry-connrefused --waitretry=5 -qO- "$url" || status=$?
2426
elif command -v curl >/dev/null 2>&1; then
25-
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url"
27+
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url" || status=$?
2628
else
2729
echo "Could not find wget or curl command" >&2
2830
return 1
2931
fi
32+
33+
if [ $status -ne 0 ]; then
34+
echo "Error streaming file from $url" >&2
35+
fi
36+
37+
return $status
3038
}
3139

3240
tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'run-build')

src/scripts/run-command.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@ sudoIfAvailable() {
1919

2020
stream() {
2121
local url="$1"
22+
local status=0
23+
2224
if command -v wget >/dev/null 2>&1; then
23-
wget --retry-connrefused --waitretry=5 -qO- "$url"
25+
wget --retry-connrefused --waitretry=5 -qO- "$url" || status=$?
2426
elif command -v curl >/dev/null 2>&1; then
25-
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url"
27+
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url" || status=$?
2628
else
2729
echo "Could not find wget or curl command" >&2
2830
return 1
2931
fi
32+
33+
if [ $status -ne 0 ]; then
34+
echo "Error streaming file from $url" >&2
35+
fi
36+
37+
return $status
3038
}
3139

3240
tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'run-command')

src/scripts/run-tests.sh

+20-4
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,43 @@ sudoIfAvailable() {
1919

2020
stream() {
2121
local url="$1"
22+
local status=0
23+
2224
if command -v wget >/dev/null 2>&1; then
23-
wget --retry-connrefused --waitretry=5 -qO- "$url"
25+
wget --retry-connrefused --waitretry=5 -qO- "$url" || status=$?
2426
elif command -v curl >/dev/null 2>&1; then
25-
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url"
27+
curl --retry 5 --retry-connrefused --retry-delay 5 -sSL "$url" || status=$?
2628
else
2729
echo "Could not find wget or curl command" >&2
2830
return 1
2931
fi
32+
33+
if [ $status -ne 0 ]; then
34+
echo "Error streaming file from $url" >&2
35+
fi
36+
37+
return $status
3038
}
3139

3240
download() {
3341
local url="$1"
3442
local filename="$2"
43+
local status=0
44+
3545
if command -v wget >/dev/null 2>&1; then
36-
wget --retry-connrefused --waitretry=5 -qO "$filename" "$url" 2>&1
46+
wget --retry-connrefused --waitretry=5 -qO "$filename" "$url" 2>&1 || status=$?
3747
elif command -v curl >/dev/null 2>&1; then
38-
curl --retry 5 --retry-all-errors --retry-delay 5 -sSLo "$filename" "$url"
48+
curl --retry 5 --retry-all-errors --retry-delay 5 -sSLo "$filename" "$url" || status=$?
3949
else
4050
echo "Could not find wget or curl command" >&2
4151
return 1
4252
fi
53+
54+
if [ $status -ne 0 ]; then
55+
echo "Error downloading file from $url to $filename" >&2
56+
fi
57+
58+
return $status
4359
}
4460

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

0 commit comments

Comments
 (0)