Skip to content

Commit

Permalink
Show better error when installed gemspecs are unreadable
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Apr 23, 2024
1 parent aac8005 commit d2657db
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bundler/lib/bundler/rubygems_ext.rb
Expand Up @@ -31,6 +31,18 @@
end

module Gem
module OpenFileWithBetterError
def open_file(path, flags, &block)
super
rescue Errno::EACCES
raise Bundler::PermissionError.new(path, :read)
end
end

class << self
prepend OpenFileWithBetterError
end

class Specification
include ::Bundler::MatchMetadata
include ::Bundler::MatchPlatform
Expand Down
23 changes: 23 additions & 0 deletions bundler/spec/commands/install_spec.rb
Expand Up @@ -1024,6 +1024,29 @@ def run
end
end

describe "when gemspecs are unreadable", :permissions do
let(:gemspec_path) { vendored_gems("specifications/rack-1.0.0.gemspec") }

before do
gemfile <<~G
source "#{file_uri_for(gem_repo1)}"
gem 'rack'
G
bundle "config path vendor/bundle"
bundle :install
expect(out).to include("Bundle complete!")
expect(err).to be_empty

FileUtils.chmod("-r", gemspec_path)
end

it "shows a good error" do
bundle :install, raise_on_error: false
expect(err).to include(gemspec_path.to_s)
expect(err).to include("grant read permissions")
end
end

context "after installing with --standalone" do
before do
install_gemfile <<-G
Expand Down

0 comments on commit d2657db

Please sign in to comment.