Skip to content

Handle Errno::EPERM errors when composing bundle #3698

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,9 @@ def compose_bundle(message)
rescue Bundler::LockfileError => e
send_message(Error.new(id: id, code: BUNDLE_COMPOSE_FAILED_CODE, message: e.message))
return
rescue Errno::EPERM
# If the user doesn't have permission to perform read operations, we can't compose the bundle
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if it makes sense to return here -- my understanding is we can't compose the bundle without more permissions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will depend on why we're getting the permission issue. When you invoke Bundler.default_lockfile, it will keep searching for a Gemfile and Gemfile.lock pair in parent directories until it reaches home.

Are we 100% sure that the permission issue is coming from reading the lockfile and not from trying to read the parent directories?

The issue could be that there's simply no bundle in the project and the user didn't give permissions to the editor for accessing any of the parent directories. In that case, returning early would not be correct because we can still compose the bundle as long as there's no lockfile and the user has permissions for the current directory.

rescue Bundler::GemfileNotFound, Errno::ENOENT
# We still compose the bundle if there's no Gemfile or if the lockfile got deleted
end
Expand Down
30 changes: 30 additions & 0 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,36 @@ def test_compose_bundle_does_not_fail_if_restarting_on_lockfile_deletion
end
end

def test_compose_bundle_does_not_fail_if_user_does_not_have_permission_to_read_lockfile
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
@server.process_message({
id: 1,
method: "initialize",
params: {
initializationOptions: {},
capabilities: { general: { positionEncodings: ["utf-8"] } },
workspaceFolders: [{ uri: URI::Generic.from_path(path: dir).to_s }],
},
})

File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gem "stringio"
GEMFILE

system("chmod 0000", Bundler.default_lockfile.to_s)

capture_subprocess_io do
@server.send(:compose_bundle, { id: 2, method: "rubyLsp/composeBundle" })&.join
end

result = find_message(RubyLsp::Result, id: 2)
assert(result.response[:success])
end
end
end

def test_does_not_index_on_did_change_watched_files_if_document_is_managed_by_client
path = File.join(Dir.pwd, "lib", "foo.rb")
source = <<~RUBY
Expand Down
Loading