Skip to content

Commit bc30fa2

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 7ea87c7 commit bc30fa2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/ruby_lsp/server.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,8 @@ def compose_bundle(message)
13901390
return
13911391
rescue Bundler::GemfileNotFound, Errno::ENOENT
13921392
# We still compose the bundle if there's no Gemfile or if the lockfile got deleted
1393+
rescue Errno::EPERM
1394+
# If the user doesn't have permission to perform read operations, we can't compose the bundle
13931395
end
13941396

13951397
# We compose the bundle in a thread so that the LSP continues to work while we're checking for its validity. Once

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)