Skip to content

Commit

Permalink
Oops, FetchError is public API. Have my cake and eat it too!
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Jun 1, 2011
1 parent c041cc5 commit 1476587
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/rubygems/commands/sources_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def execute
rescue URI::Error, ArgumentError
say "#{source_uri} is not a URI"
terminate_interaction 1
rescue Gem::RemoteFetcher::FetchError, Gem::SourceError => e
rescue Gem::RemoteFetcher::FetchError => e
say "Error fetching #{source_uri}:\n\t#{e.message}"
terminate_interaction 1
end
Expand Down
17 changes: 0 additions & 17 deletions lib/rubygems/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,3 @@ def initialize(exit_code)

end

##
# An error that indicates there is an error with the source
# itself (such as the latest_spec file being invalid)

class Gem::SourceError < Gem::Exception
def initialize(message, uri)
@uri = uri
super message
end

attr_reader :uri

def to_s
"#{super} (#{@uri})"
end
end

22 changes: 6 additions & 16 deletions lib/rubygems/spec_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,12 @@ def load_specs(source_uri, file)
local_file = File.join(cache_dir, file_name)
retried = false

begin
spec_dump = if @update_cache then
FileUtils.mkdir_p cache_dir
@fetcher.cache_update_path(spec_path, local_file)
else
@fetcher.cache_update_path(spec_path)
end
rescue Gem::RemoteFetcher::UnknownHostError => e
exc = Gem::SourceError.new("Could not contact source", source_uri)
exc.source_exception = e
raise exc
rescue Gem::RemoteFetcher::FetchError => e
exc = Gem::SourceError.new("Bad source, unable to get specs", source_uri)
exc.source_exception = e
raise exc
end
spec_dump = if @update_cache then
FileUtils.mkdir_p cache_dir
@fetcher.cache_update_path(spec_path, local_file)
else
@fetcher.cache_update_path(spec_path)
end

begin
Marshal.load spec_dump
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_commands_sources_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_execute_add_nonexistent_source

expected = <<-EOF
Error fetching http://beta-gems.example.com:
\tBad source, unable to get specs (http://beta-gems.example.com)
\tit died (#{uri})
EOF

assert_equal expected, @ui.output
Expand Down

0 comments on commit 1476587

Please sign in to comment.