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

Fix exception output capturing #482

Merged
merged 1 commit into from
Oct 16, 2024
Merged
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
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to avoid deleting the params here since they may be needed in the error message.

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))
Copy link
Contributor Author

@andyw8 andyw8 Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinistock I updated this so that we show the request name for both rescue clauses.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log_message just writes to $stderr, which we are already capturing.

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
Loading