Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) Handle an invalid mirror gracefully #813

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](https://semver.org).
This changelog adheres to [Keep a CHANGELOG](https://keepachangelog.com).

## [Unreleased]
### Fixed
- (maint) Handle an invalid mirror gracefully

## [0.39.1] - release 2023-08-25
### Fixed
Expand Down
11 changes: 9 additions & 2 deletions lib/vanagon/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,21 @@ 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::InvalidSource
# 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 %(Invalid source "#{mirror}")
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
7 changes: 5 additions & 2 deletions lib/vanagon/component/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
require 'vanagon/component/source/http'
require 'vanagon/component/source/git'
require 'vanagon/component/source/local'
require 'vanagon/errors'

class Vanagon
class InvalidSource < Vanagon::Error
end
class Component
class Source
SUPPORTED_PROTOCOLS = %w[file http https git].freeze
Expand Down Expand Up @@ -55,8 +58,8 @@ def source(uri_instance, **options) # rubocop:disable Metrics/AbcSize
end

# Unknown source type!
raise Vanagon::Error,
"Unknown file type: '#{uri}'; cannot continue"
raise Vanagon::InvalidSource,
"Source is invalid or of an unknown type: '#{uri}'; cannot continue"
end

def determine_source_type(uri)
Expand Down