Skip to content

Commit 7b14e01

Browse files
Merge pull request #7603 from rubygems/deivid-rodriguez/better-unreadable-error
Show better error when installed gemspecs are unreadable (cherry picked from commit 4e7e56f)
1 parent 8d28776 commit 7b14e01

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

bundler/lib/bundler/rubygems_ext.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ def dependencies_to_gemfile(dependencies, group = nil)
146146
end
147147
end
148148

149+
module BetterPermissionError
150+
def data
151+
Bundler::SharedHelpers.filesystem_access(loaded_from, :read) do
152+
super
153+
end
154+
end
155+
end
156+
157+
class StubSpecification
158+
prepend BetterPermissionError
159+
end
160+
149161
class Dependency
150162
include ::Bundler::ForcePlatform
151163

bundler/spec/commands/install_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,29 @@ def run
10241024
end
10251025
end
10261026

1027+
describe "when gemspecs are unreadable", :permissions do
1028+
let(:gemspec_path) { vendored_gems("specifications/rack-1.0.0.gemspec") }
1029+
1030+
before do
1031+
gemfile <<~G
1032+
source "#{file_uri_for(gem_repo1)}"
1033+
gem 'rack'
1034+
G
1035+
bundle "config path vendor/bundle"
1036+
bundle :install
1037+
expect(out).to include("Bundle complete!")
1038+
expect(err).to be_empty
1039+
1040+
FileUtils.chmod("-r", gemspec_path)
1041+
end
1042+
1043+
it "shows a good error" do
1044+
bundle :install, raise_on_error: false
1045+
expect(err).to include(gemspec_path.to_s)
1046+
expect(err).to include("grant read permissions")
1047+
end
1048+
end
1049+
10271050
context "after installing with --standalone" do
10281051
before do
10291052
install_gemfile <<-G

0 commit comments

Comments
 (0)