Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
abstract Marshal.load failures
Browse files Browse the repository at this point in the history
  • Loading branch information
indirect committed Feb 19, 2013
1 parent 332cd2f commit bfc0632
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions lib/bundler.rb
Expand Up @@ -81,6 +81,7 @@ def initialize(conflicts, msg = nil)
end

class InvalidSpecSet < StandardError; end
class MarshalError < StandardError; end

class << self
attr_writer :ui, :bundle_path
Expand Down Expand Up @@ -284,6 +285,12 @@ def read_file(file)
File.open(file, "rb") { |f| f.read }
end

def load_marshal(data)
Marshal.load(data)
rescue => e
raise MarshalError, "#{e.class}: #{e.message}"
end

def load_gemspec(file)
@gemspec_cache ||= {}
key = File.expand_path(file)
Expand Down
13 changes: 8 additions & 5 deletions lib/bundler/fetcher.rb
Expand Up @@ -83,7 +83,10 @@ def fetch_spec(spec)
uri = URI.parse("#{@remote_uri}#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}")

spec_rz = (uri.scheme == "file") ? Gem.read_binary(uri.path) : fetch(uri)
Marshal.load Gem.inflate(spec_rz)
Bundler.load_marshal Gem.inflate(spec_rz)
rescue MarshalError => e
raise HTTPError, "Gemspec #{spec} contained invalid data.\n" \
"Your network or your gem server is probably having issues right now."
end

# return the specs in the bundler format as an index
Expand Down Expand Up @@ -143,9 +146,9 @@ def fetch_remote_specs(gem_names, full_dependency_list = [], last_spec_list = []
fetch_remote_specs(deps_list, full_dependency_list + returned_gems, spec_list + last_spec_list)
# fall back to the legacy index in the following cases
# 1. Gemcutter Endpoint doesn't return a 200
# 2,3. Marshal blob doesn't load properly
# 4. One of the YAML gemspecs has the Syck::DefaultKey problem
rescue HTTPError, ArgumentError, TypeError, GemspecError => e
# 2. Marshal blob doesn't load properly
# 3. One of the YAML gemspecs has the Syck::DefaultKey problem
rescue HTTPError, MarshalError, GemspecError => e
@use_api = false

# new line now that the dots are over
Expand Down Expand Up @@ -226,7 +229,7 @@ def dependency_api_uri(gem_names = [])
def fetch_dependency_remote_specs(gem_names)
Bundler.ui.debug "Query Gemcutter Dependency Endpoint API: #{gem_names.join(',')}"
marshalled_deps = fetch dependency_api_uri(gem_names)
gem_list = Marshal.load(marshalled_deps)
gem_list = Bundler.load_marshal(marshalled_deps)
deps_list = []

spec_list = gem_list.map do |s|
Expand Down

0 comments on commit bfc0632

Please sign in to comment.