diff --git a/lib/ruby_lsp/setup_bundler.rb b/lib/ruby_lsp/setup_bundler.rb index d358d01c9a..811dea1774 100644 --- a/lib/ruby_lsp/setup_bundler.rb +++ b/lib/ruby_lsp/setup_bundler.rb @@ -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 diff --git a/test/setup_bundler_test.rb b/test/setup_bundler_test.rb index 12c8d6a82c..94fc0d82dc 100644 --- a/test/setup_bundler_test.rb +++ b/test/setup_bundler_test.rb @@ -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