Skip to content

Commit 7ea87c7

Browse files
committed
Handle Bundler::Fetcher::NetworkDownError during Bundler setup
We occasionally receive reports of `Bundler::Fetcher::NetworkDownError`s happening in our telemetry. We expect errors like this occasionally and seeing them in telemetry does not really help us. For now, we can handle these errors so they don't get written to our error logging file.
1 parent 3565a97 commit 7ea87c7

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

lib/ruby_lsp/setup_bundler.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,14 @@ def run_bundle_install(bundle_gemfile = @gemfile)
234234
# If no error occurred, then clear previous errors
235235
@error_path.delete if @error_path.exist?
236236
$stderr.puts("Ruby LSP> Composed bundle installation complete")
237-
rescue Errno::EPIPE
238-
# If the $stderr pipe was closed by the client, for example when closing the editor during running bundle
239-
# install, we don't want to write the error to a file or else we will report to telemetry on the next launch and
240-
# it does not represent an actual error.
237+
rescue Errno::EPIPE, Bundler::Fetcher::NetworkDownError
238+
# There are cases where we expect certain errors to happen occasionally, and we don't want to write them to
239+
# a file, which would report to telemetry on the next launch.
241240
#
242-
# This situation may happen because while running bundle install, the server is not yet ready to receive
243-
# shutdown requests and we may continue doing work until the process is killed.
241+
# - The $stderr pipe might be closed by the client, for example when closing the editor during running bundle
242+
# install. This situation may happen because, while running bundle install, the server is not yet ready to
243+
# receive shutdown requests and we may continue doing work until the process is killed.
244+
# - Bundler might also encounter a network error.
244245
@error_path.delete if @error_path.exist?
245246
rescue => e
246247
# Write the error object to a file so that we can read it from the parent process

test/setup_bundler_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,27 @@ def test_ignores_bundle_package
914914
end
915915
end
916916

917+
def test_handles_network_down_error_during_bundle_install
918+
Dir.mktmpdir do |dir|
919+
Dir.chdir(dir) do
920+
File.write(File.join(dir, "gems.rb"), <<~GEMFILE)
921+
source "https://rubygems.org"
922+
gem "irb"
923+
GEMFILE
924+
925+
Bundler.with_unbundled_env do
926+
system("bundle install")
927+
928+
compose = RubyLsp::SetupBundler.new(dir, launcher: true)
929+
compose.expects(:bundle_check).raises(Bundler::Fetcher::NetworkDownError)
930+
compose.setup!
931+
932+
refute_path_exists(File.join(dir, ".ruby-lsp", "install_error"))
933+
end
934+
end
935+
end
936+
end
937+
917938
def test_is_resilient_to_pipe_being_closed_by_client_during_compose
918939
Dir.mktmpdir do |dir|
919940
Dir.chdir(dir) do

0 commit comments

Comments
 (0)