Skip to content

Commit

Permalink
Fix exception output capturing (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 authored Oct 16, 2024
1 parent 9cc59fc commit 0c98405
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions lib/ruby_lsp/ruby_lsp_rails/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def send_message(message)
@stdout.write("Content-Length: #{json_message.length}\r\n\r\n#{json_message}")
end

# Log a debug message to the editor's output
def debug_message(message)
# Log a message to the editor's output panel
def log_message(message)
$stderr.puts(message)
end
end
Expand Down Expand Up @@ -119,12 +119,17 @@ def execute(request, params)
require params[:server_addon_path]
ServerAddon.finalize_registrations!(@stdout)
when "server_addon/delegate"
server_addon_name = params.delete(:server_addon_name)
request_name = params.delete(:request_name)
ServerAddon.delegate(server_addon_name, request_name, params)
server_addon_name = params[:server_addon_name]
request_name = params[:request_name]
ServerAddon.delegate(server_addon_name, request_name, params.except(:request_name, :server_addon_name))
end
request_name = request
request_name = "#{params[:server_addon_name]}##{params[:request_name]}" if request == "server_addon/delegate"
# Since this is a common problem, we show a specific error message to the user, instead of the full stack trace.
rescue ActiveRecord::ConnectionNotEstablished
log_message("Request #{request_name} failed because database connection was not established.")
rescue => e
send_message({ error: e.full_message(highlight: false) })
log_message("Request #{request_name} failed:\n" + e.full_message(highlight: false))
end

private
Expand Down
2 changes: 1 addition & 1 deletion test/ruby_lsp_rails/runner_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def name
end
def execute(request, params)
debug_message("Hello!")
log_message("Hello!")
send_message({ request:, params: })
end
end
Expand Down

0 comments on commit 0c98405

Please sign in to comment.