Skip to content

Commit 3e45f8c

Browse files
committed
Handle JSON parse error
1 parent b18db20 commit 3e45f8c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/ruby_lsp/ruby_lsp_rails/runner_client.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ def send_message(request, params = nil)
6161
def read_response
6262
headers = @stdout.gets("\r\n\r\n")
6363
raw_response = @stdout.read(T.must(headers)[/Content-Length: (\d+)/i, 1].to_i)
64-
response = JSON.parse(T.must(raw_response), symbolize_names: true)
6564

66-
# TODO: handle exception if JSON parse fails?
65+
response = begin
66+
JSON.parse(T.must(raw_response), symbolize_names: true)
67+
rescue JSON::ParserError => e
68+
{ error: e.message }
69+
end
6770

6871
if response[:error]
6972
warn("Ruby LSP Rails error: " + response[:error])

0 commit comments

Comments
 (0)