Commit 262eb165 authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

Clearer error message when HTTP download fails

Previously, if `http get` failed, the `download_tarball` function would
still continue since the ERR trap had no effect at that point.

Given a script in the form of `{ ... } || return 1`, the expressions
that are the part of the first group are not subject to ERR trap since
they are non-last in a chain of expressions.

However, since we still can't count on the ERR trap taking effect in
this phase, better just rewrite the function to manually abort.

Fixes #394
parent 85f54709
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -283,9 +283,12 @@ download_tarball() {

  echo "-> $package_url" >&2

  { http get "$package_url" "$package_filename"
    verify_checksum "$package_filename" "$checksum"
  } >&4 2>&1 || return 1
  if http get "$package_url" "$package_filename" >&4 2>&1; then
    verify_checksum "$package_filename" "$checksum" >&4 2>&1 || return 1
  else
    echo "error: failed to download $package_filename" >&2
    return 1
  fi

  if [ -n "$RUBY_BUILD_CACHE_PATH" ]; then
    local cached_package_filename="${RUBY_BUILD_CACHE_PATH}/$package_filename"

test/fetch.bats

0 → 100644
+14 −0
Original line number Diff line number Diff line
#!/usr/bin/env bats

load test_helper
export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH=

@test "failed download displays error message" {
  stub curl false

  install_fixture definitions/without-checksum
  assert_failure
  assert_output_contains "> http://example.com/packages/package-1.0.0.tar.gz"
  assert_output_contains "error: failed to download package-1.0.0.tar.gz"
}
+9 −0
Original line number Diff line number Diff line
@@ -94,3 +94,12 @@ assert_output() {
  fi
  assert_equal "$expected" "$output"
}

assert_output_contains() {
  local expected="$1"
  echo "$output" | grep -F "$expected" >/dev/null || {
    { echo "expected output to contain $expected"
      echo "actual: $output"
    } | flunk
  }
}