Skip to content

Commit be9cea2

Browse files
authored
Avoid sending invalid location errors to telemetry (#3682)
1 parent c9c4272 commit be9cea2

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/ruby_lsp/server.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,12 @@ def process_message(message)
126126
if message[:id]
127127
# If a document is deleted before we are able to process all of its enqueued requests, we will try to read it
128128
# from disk and it raise this error. This is expected, so we don't include the `data` attribute to avoid
129-
# reporting these to our telemetry
130-
if e.is_a?(Store::NonExistingDocumentError)
129+
# reporting these to our telemetry.
130+
#
131+
# Similarly, if we receive a location for an invalid position in the
132+
# document, we don't report it to telemetry
133+
case e
134+
when Store::NonExistingDocumentError, Document::InvalidLocationError
131135
send_message(Error.new(
132136
id: message[:id],
133137
code: Constant::ErrorCodes::INVALID_PARAMS,

test/server_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,38 @@ def version
15671567
end
15681568
end
15691569

1570+
def test_invalid_location_errors_are_not_reported_to_telemetry
1571+
uri = URI::Generic.from_path(path: "/foo.rb")
1572+
1573+
@server.process_message({
1574+
method: "textDocument/didOpen",
1575+
params: {
1576+
textDocument: {
1577+
uri: uri,
1578+
text: "class Foo\nend",
1579+
version: 1,
1580+
languageId: "ruby",
1581+
},
1582+
},
1583+
})
1584+
1585+
@server.push_message({
1586+
id: 1,
1587+
method: "textDocument/definition",
1588+
params: {
1589+
textDocument: {
1590+
uri: uri,
1591+
},
1592+
position: { line: 10, character: 6 },
1593+
},
1594+
})
1595+
1596+
error = find_message(RubyLsp::Error)
1597+
attributes = error.to_hash[:error]
1598+
assert_nil(attributes[:data])
1599+
assert_match("Document::InvalidLocationError", attributes[:message])
1600+
end
1601+
15701602
private
15711603

15721604
def wait_for_indexing

0 commit comments

Comments
 (0)