Skip to content

Commit

Permalink
Handle an invalid mirror gracefully
Browse files Browse the repository at this point in the history
Because the HTTP source's valid_url? check was always returning truthy before, a mirror URL to a file would always seem to be valid, even if it wasn't. Now that 9995d5e fixed it, a Vanagon::Error would get thrown saying it was an unknown file type. This means that fetch_url would never get called since this exception in fetch_mirrors would be unhandled.

This handles that particular error, and continues to throw other Vanagon::Error types, as they usually indicate a problem with the definition of the component or some other type of fatal error. Additionally, this changes the catching of RuntimeError to StandardError, so that we can handle issues talking to the particular URL, such as OpenSSL errors.
  • Loading branch information
Nick Burgan-Illig committed Aug 28, 2023
1 parent 544a2c7 commit 2b47423
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/vanagon/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,28 @@ def fetch_mirrors(options)
VanagonLogger.info %(Attempting to fetch from mirror URL "#{mirror}")
@source = Vanagon::Component::Source.source(mirror, **options)
return true if source.fetch
rescue Vanagon::Error => e
if e.message =~ /Unknown file type/
# This means that the URL was not a git repo or a valid downloadable file,
# which means either the URL is incorrect, or we don't have access to that
# resource. Return false, so that the pkg.url value can be used instead.
VanagonLogger.error %(Unable to access mirror URL "#{mirror}")
else
# Otherwise, a Vanagon::Error indicates there's something wrong with
# the way the component is defined, or some other fatal issue,
# and we want to expose that.
raise
end
rescue SocketError
# SocketError means that there was no DNS/name resolution
# for whatever remote protocol the mirror tried to use.
VanagonLogger.error %(Unable to resolve mirror URL "#{mirror}")
rescue RuntimeError
rescue StandardError
# Source retrieval does not consistently return a meaningful
# namespaced error message, which means we're brute-force rescuing
# RuntimeError. Not a good look, and we should fix this.
# StandardError. Also, we want to handle other unexpected things when
# we try reaching out to the URL, so that we can gracefully return
# false and fall back to fetching the pkg.url value instead.
VanagonLogger.error %(Unable to retrieve mirror URL "#{mirror}")
end
end
Expand Down

0 comments on commit 2b47423

Please sign in to comment.