Skip to content

Commit 967f12d

Browse files
committed
Filter GemNotFound and GitError setup errors from telemetry
When Bundler.setup fails with these errors, the server already recovers gracefully into degraded mode. Reporting them creates noise since they are user environment issues (missing gems or bad git refs in Gemfile).
1 parent e492623 commit 967f12d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/ruby_lsp/server.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
module RubyLsp
55
class Server < BaseServer
6+
NON_REPORTABLE_SETUP_ERRORS = [Bundler::GemNotFound, Bundler::GitError].freeze #: Array[singleton(StandardError)]
7+
68
# Only for testing
79
#: GlobalState
810
attr_reader :global_state
@@ -315,7 +317,7 @@ def run_initialize(message)
315317

316318
global_state_notifications.each { |notification| send_message(notification) }
317319

318-
if @setup_error
320+
if @setup_error && NON_REPORTABLE_SETUP_ERRORS.none? { |error_class| @setup_error.is_a?(error_class) }
319321
send_message(Notification.telemetry(
320322
type: "error",
321323
errorMessage: @setup_error.message,

test/server_test.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,21 @@ def test_errors_include_telemetry_data
647647
assert_match("mocha/exception_raiser.rb", data[:backtrace])
648648
end
649649

650+
def test_gem_not_found_setup_error_does_not_send_telemetry
651+
RubyLsp::Notification.expects(:telemetry).never
652+
run_initialize_server_with_setup_error(Bundler::GemNotFound.new("Could not find gem 'foo'"))
653+
end
654+
655+
def test_git_error_setup_error_does_not_send_telemetry
656+
RubyLsp::Notification.expects(:telemetry).never
657+
run_initialize_server_with_setup_error(Bundler::GitError.new("Revision abc123 does not exist"))
658+
end
659+
660+
def test_other_setup_errors_are_reported_to_telemetry
661+
RubyLsp::Notification.expects(:telemetry).once
662+
run_initialize_server_with_setup_error(StandardError.new("something unexpected"))
663+
end
664+
650665
def test_handles_editor_indexing_settings
651666
capture_io do
652667
@server.process_message({
@@ -1714,6 +1729,22 @@ def test_launch_bundle_compose_forwards_argv_to_launcher
17141729

17151730
private
17161731

1732+
def run_initialize_server_with_setup_error(error)
1733+
server = RubyLsp::Server.new(test_mode: true, setup_error: error)
1734+
capture_subprocess_io do
1735+
server.process_message({
1736+
id: 1,
1737+
method: "initialize",
1738+
params: {
1739+
initializationOptions: { enabledFeatures: [] },
1740+
capabilities: { general: { positionEncodings: ["utf-8"] } },
1741+
},
1742+
})
1743+
end
1744+
ensure
1745+
server&.run_shutdown
1746+
end
1747+
17171748
def wait_for_indexing
17181749
message = @server.pop_response
17191750
until message.is_a?(RubyLsp::Notification) && message.method == "$/progress" &&

0 commit comments

Comments
 (0)