Skip to content

Commit 474a760

Browse files
committed
Handle Bundler::HTTPErrors during bundle install
It turns out, `Bundler::Fetcher::NetworkDownError` is actually a subclass of `Bundler::HTTPError`, and both have shown up in our telemetry. By rescuing only `Bundler::HTTPError`, we also rescue all subclasses that might indicate other bundler networking errors as well.
1 parent 9a027cf commit 474a760

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/ruby_lsp/setup_bundler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ 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, Bundler::Fetcher::NetworkDownError
237+
rescue Errno::EPIPE, Bundler::HTTPError
238238
# There are cases where we expect certain errors to happen occasionally, and we don't want to write them to
239239
# a file, which would report to telemetry on the next launch.
240240
#

test/setup_bundler_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,27 @@ def test_handles_network_down_error_during_bundle_install
935935
end
936936
end
937937

938+
def test_handles_http_error_during_bundle_install
939+
Dir.mktmpdir do |dir|
940+
Dir.chdir(dir) do
941+
File.write(File.join(dir, "gems.rb"), <<~GEMFILE)
942+
source "https://rubygems.org"
943+
gem "irb"
944+
GEMFILE
945+
946+
Bundler.with_unbundled_env do
947+
system("bundle install")
948+
949+
compose = RubyLsp::SetupBundler.new(dir, launcher: true)
950+
compose.expects(:bundle_check).raises(Bundler::HTTPError)
951+
compose.setup!
952+
953+
refute_path_exists(File.join(dir, ".ruby-lsp", "install_error"))
954+
end
955+
end
956+
end
957+
end
958+
938959
def test_is_resilient_to_pipe_being_closed_by_client_during_compose
939960
Dir.mktmpdir do |dir|
940961
Dir.chdir(dir) do

0 commit comments

Comments
 (0)