Skip to content

Commit

Permalink
Show a proper error if gem path is not writable
Browse files Browse the repository at this point in the history
Instead of showing the bug report place with an error at a randome
place.
  • Loading branch information
deivid-rodriguez committed Oct 14, 2021
1 parent 6955f47 commit 241854c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
16 changes: 14 additions & 2 deletions bundler/lib/bundler/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,22 @@ def action
end
end

def permission_type
case @permission_type
when :create
"executable permissions for all parent directories and write permissions for `#{parent_folder}`"
else
"#{@permission_type} permissions for that path"
end
end

def parent_folder
File.dirname(@path)
end

def message
"There was an error while trying to #{action} `#{@path}`. " \
"It is likely that you need to grant #{@permission_type} permissions " \
"for that path."
"It is likely that you need to grant #{permission_type}."
end

status_code(23)
Expand Down
4 changes: 3 additions & 1 deletion bundler/lib/bundler/rubygems_gem_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def install
FileUtils.rm_rf gem_dir
FileUtils.rm_rf spec.extension_dir

FileUtils.mkdir_p gem_dir, :mode => 0o755
SharedHelpers.filesystem_access(gem_dir, :create) do
FileUtils.mkdir_p gem_dir, :mode => 0o755
end

extract_files

Expand Down
30 changes: 30 additions & 0 deletions bundler/spec/commands/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,36 @@ def run
end
end

describe "when bundle gems path does not have write access", :permissions do
let(:gems_path) { bundled_app("vendor/#{Bundler.ruby_scope}/gems") }

before do
FileUtils.mkdir_p(gems_path)
gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem 'rack'
G
end

it "should display a proper message to explain the problem" do
FileUtils.chmod("-x", gems_path)
bundle "config set --local path vendor"

begin
bundle :install, :raise_on_error => false
ensure
FileUtils.chmod("+x", gems_path)
end

expect(err).not_to include("ERROR REPORT TEMPLATE")

expect(err).to include(
"There was an error while trying to create `#{gems_path.join("rack-1.0.0")}`. " \
"It is likely that you need to grant executable permissions for all parent directories and write permissions for `#{gems_path}`."
)
end
end

describe "when bundle cache path does not have write access", :permissions do
let(:cache_path) { bundled_app("vendor/#{Bundler.ruby_scope}/cache") }

Expand Down

0 comments on commit 241854c

Please sign in to comment.