Skip to content

Commit

Permalink
improve error handling in mason try binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Oct 30, 2017
1 parent 638e35e commit 1727795
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions mason.sh
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ function mason_download {
cd "${MASON_ROOT}/.cache"
if [ ! -f ${MASON_SLUG} ] ; then
mason_step "Downloading $1..."
CURL_RESULT=0
local CURL_RESULT=0
curl --retry 3 ${MASON_CURL_ARGS} -f -S -L "$1" -o ${MASON_SLUG} || CURL_RESULT=$?
if [[ ${CURL_RESULT} != 0 ]]; then
mason_error "Failed to download ${1} (returncode: $CURL_RESULT)"
Expand Down Expand Up @@ -526,21 +526,30 @@ function mason_write_config {
function mason_try_binary {
MASON_BINARIES_DIR=`dirname "${MASON_BINARIES}"`
mkdir -p "${MASON_ROOT}/.binaries/${MASON_BINARIES_DIR}"
local FULL_URL="https://${MASON_BUCKET}.s3.amazonaws.com/${MASON_BINARIES}"

# try downloading from S3
if [ ! -f "${MASON_BINARIES_PATH}" ] ; then
mason_step "Downloading binary package ${MASON_BINARIES}..."
curl --retry 3 ${MASON_CURL_ARGS} -f -L \
https://${MASON_BUCKET}.s3.amazonaws.com/${MASON_BINARIES} \
-o "${MASON_BINARIES_PATH}.tmp" && \
mv "${MASON_BINARIES_PATH}.tmp" "${MASON_BINARIES_PATH}" || \
mason_step "Binary not available yet for https://${MASON_BUCKET}.s3.amazonaws.com/${MASON_BINARIES}"
mason_step "Downloading binary package ${FULL_URL}"
local CURL_RESULT=0
local HTTP_RETURN=0
HTTP_RETURN=$(curl -w "%{http_code}" --retry 3 ${MASON_CURL_ARGS} -f -L ${FULL_URL} -o "${MASON_BINARIES_PATH}.tmp") || CURL_RESULT=$?
if [[ ${CURL_RESULT} != 0 ]]; then
if [[ ${HTTP_RETURN} == "403" ]]; then
mason_step "Binary not available for ${FULL_URL}"
else
mason_error "Failed to download ${FULL_URL} (returncode: ${CURL_RESULT})"
exit $CURL_RESULT
fi
else
mv "${MASON_BINARIES_PATH}.tmp" "${MASON_BINARIES_PATH}"
fi
else
mason_step "Updating binary package ${MASON_BINARIES}..."
curl --retry 3 ${MASON_CURL_ARGS} -f -L -z "${MASON_BINARIES_PATH}" \
https://${MASON_BUCKET}.s3.amazonaws.com/${MASON_BINARIES} \
-o "${MASON_BINARIES_PATH}.tmp"
if [ $? -eq 0 ] ; then
local CURL_RESULT=0
local HTTP_RETURN=0
HTTP_RETURN=$(curl -w "%{http_code}" --retry 3 ${MASON_CURL_ARGS} -f -L -z "${MASON_BINARIES_PATH}" -o "${MASON_BINARIES_PATH}.tmp") || CURL_RESULT=$?

This comment has been minimized.

Copy link
@lightmare

lightmare Aug 23, 2019

Collaborator

@springmeyer The FULL_URL is missing here and curl complains: curl: no URL specified!

This comment has been minimized.

Copy link
@springmeyer

springmeyer Aug 23, 2019

Contributor

thanks for noticing, would you like commit access to quickly fix bugs like this yourself - or are you good with PRs still?

if [[ ${CURL_RESULT} != 0 ]]; then
if [ -f "${MASON_BINARIES_PATH}.tmp" ]; then
mv "${MASON_BINARIES_PATH}.tmp" "${MASON_BINARIES_PATH}"
else
Expand Down

1 comment on commit 1727795

@lightmare
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could use commit access for small fixes, yes.

Please sign in to comment.