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

Show better error when installed gemspecs are unreadable #7603

Merged
merged 1 commit into from Apr 29, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions bundler/lib/bundler/rubygems_ext.rb
Expand Up @@ -146,6 +146,18 @@ def dependencies_to_gemfile(dependencies, group = nil)
end
end

module BetterPermissionError
def data
Bundler::SharedHelpers.filesystem_access(loaded_from, :read) do
super
end
end
end

class StubSpecification
prepend BetterPermissionError
end

class Dependency
include ::Bundler::ForcePlatform

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