Skip to content

Commit f0b38fd

Browse files
committed
Handle Errno::EPERM errors when composing bundle
Some of these errors have been reported to our telemetry. For now, it makes sense to rescue the error and ignore it because it means that the user's environment does not have permissions to read their lockfile, which means we can't compose the bundle.
1 parent 474a760 commit f0b38fd

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/ruby_lsp/server.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,9 @@ def compose_bundle(message)
13881388
rescue Bundler::LockfileError => e
13891389
send_message(Error.new(id: id, code: BUNDLE_COMPOSE_FAILED_CODE, message: e.message))
13901390
return
1391+
rescue Errno::EPERM
1392+
# If the user doesn't have permission to perform read operations, we can't compose the bundle
1393+
return
13911394
rescue Bundler::GemfileNotFound, Errno::ENOENT
13921395
# We still compose the bundle if there's no Gemfile or if the lockfile got deleted
13931396
end

test/server_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,36 @@ def test_compose_bundle_does_not_fail_if_restarting_on_lockfile_deletion
12141214
end
12151215
end
12161216

1217+
def test_compose_bundle_does_not_fail_if_user_does_not_have_permission_to_read_lockfile
1218+
Dir.mktmpdir do |dir|
1219+
Dir.chdir(dir) do
1220+
@server.process_message({
1221+
id: 1,
1222+
method: "initialize",
1223+
params: {
1224+
initializationOptions: {},
1225+
capabilities: { general: { positionEncodings: ["utf-8"] } },
1226+
workspaceFolders: [{ uri: URI::Generic.from_path(path: dir).to_s }],
1227+
},
1228+
})
1229+
1230+
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
1231+
source "https://rubygems.org"
1232+
gem "stringio"
1233+
GEMFILE
1234+
1235+
system("chmod 0000", Bundler.default_lockfile.to_s)
1236+
1237+
capture_subprocess_io do
1238+
@server.send(:compose_bundle, { id: 2, method: "rubyLsp/composeBundle" })&.join
1239+
end
1240+
1241+
result = find_message(RubyLsp::Result, id: 2)
1242+
assert(result.response[:success])
1243+
end
1244+
end
1245+
end
1246+
12171247
def test_does_not_index_on_did_change_watched_files_if_document_is_managed_by_client
12181248
path = File.join(Dir.pwd, "lib", "foo.rb")
12191249
source = <<~RUBY

0 commit comments

Comments
 (0)