Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore unrecoverable Bundler errors for telemetry #3078

Closed
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
50 changes: 32 additions & 18 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,24 +310,7 @@ def run_initialize(message)
begin_progress("indexing-progress", "Ruby LSP: indexing files")

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

if @setup_error
send_message(Notification.telemetry(
type: "error",
errorMessage: @setup_error.message,
errorClass: @setup_error.class,
stack: @setup_error.backtrace&.join("\n"),
))
end

if @install_error
send_message(Notification.telemetry(
type: "error",
errorMessage: @install_error.message,
errorClass: @install_error.class,
stack: @install_error.backtrace&.join("\n"),
))
end
report_bundle_errors
end

sig { void }
Expand Down Expand Up @@ -1282,5 +1265,36 @@ def window_show_message_request(message)

addon.handle_window_show_message_response(result[:title])
end

sig { void }
def report_bundle_errors
unrecoverable_setup_errors = [
Bundler::PathError, # E.g.: using `path:` in the Gemfile and pointing to a non-existing directory
]

if @setup_error && !unrecoverable_setup_errors.include?(@setup_error.class)
send_message(Notification.telemetry(
type: "error",
errorMessage: @setup_error.message,
errorClass: @setup_error.class,
stack: @setup_error.backtrace&.join("\n"),
))
end

unrecoverable_install_errors = [
Bundler::HTTPError, # An HTTP error occurred when trying to download gems
Bundler::Fetcher::NetworkDownError, # A network error happened when trying to fetch specs from RubyGems
Bundler::InstallError, # Failed to install a gem. Usually happens with native extensions
]

if @install_error && !unrecoverable_install_errors.include?(@install_error.class)
send_message(Notification.telemetry(
type: "error",
errorMessage: @install_error.message,
errorClass: @install_error.class,
stack: @install_error.backtrace&.join("\n"),
))
end
end
end
end
32 changes: 32 additions & 0 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,38 @@ def test_rubocop_config_changes_trigger_workspace_diagnostic_refresh
assert_equal("workspace/diagnostic/refresh", request.method)
end

def test_does_not_report_unrecoverable_bundler_errors
server = RubyLsp::Server.new(
test_mode: true,
install_error: Bundler::Fetcher::NetworkDownError.new("boom"),
setup_error: Bundler::PathError.new("boom"),
)

server.process_message({
id: 1,
method: "initialize",
params: {
initializationOptions: { enabledFeatures: [] },
capabilities: { general: { positionEncodings: ["utf-8"] } },
},
})

6.times do
message = server.pop_response
next unless message.is_a?(RubyLsp::Notification)

refute_equal("telemetry/event", message.method)
end

begin
assert_raises(Timeout::Error) do
Timeout.timeout(0.2) { server.pop_response }
end
ensure
server.run_shutdown
end
end

private

def with_uninstalled_rubocop(&block)
Expand Down
Loading