Skip to content
Merged
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
13 changes: 7 additions & 6 deletions lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,14 @@ def run_bundle_install(bundle_gemfile = @gemfile)
# If no error occurred, then clear previous errors
@error_path.delete if @error_path.exist?
$stderr.puts("Ruby LSP> Composed bundle installation complete")
rescue Errno::EPIPE
# If the $stderr pipe was closed by the client, for example when closing the editor during running bundle
# install, we don't want to write the error to a file or else we will report to telemetry on the next launch and
# it does not represent an actual error.
rescue Errno::EPIPE, Bundler::Fetcher::NetworkDownError
# There are cases where we expect certain errors to happen occasionally, and we don't want to write them to
# a file, which would report to telemetry on the next launch.
#
# This situation may happen because while running bundle install, the server is not yet ready to receive
# shutdown requests and we may continue doing work until the process is killed.
# - The $stderr pipe might be closed by the client, for example when closing the editor during running bundle
# install. This situation may happen because, while running bundle install, the server is not yet ready to
# receive shutdown requests and we may continue doing work until the process is killed.
# - Bundler might also encounter a network error.
@error_path.delete if @error_path.exist?
rescue => e
# Write the error object to a file so that we can read it from the parent process
Expand Down
21 changes: 21 additions & 0 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,27 @@ def test_ignores_bundle_package
end
end

def test_handles_network_down_error_during_bundle_install
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
File.write(File.join(dir, "gems.rb"), <<~GEMFILE)
source "https://rubygems.org"
gem "irb"
GEMFILE

Bundler.with_unbundled_env do
system("bundle install")

compose = RubyLsp::SetupBundler.new(dir, launcher: true)
compose.expects(:bundle_check).raises(Bundler::Fetcher::NetworkDownError)
compose.setup!

refute_path_exists(File.join(dir, ".ruby-lsp", "install_error"))
end
end
end
end

def test_is_resilient_to_pipe_being_closed_by_client_during_compose
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
Expand Down
Loading