Skip to content

Improve fault tolerance of addon delegation requests #572

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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: 13 additions & 4 deletions lib/ruby_lsp/ruby_lsp_rails/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ def send_notification(message)
class ServerAddon
include Common

class MissingAddonError < StandardError; end

@server_addon_classes = []
@server_addons = {}

Expand All @@ -171,7 +173,10 @@ def inherited(child)

# Delegate `request` with `params` to the server add-on with the given `name`
def delegate(name, request, params)
@server_addons[name]&.execute(request, params)
addon = @server_addons.fetch(name) do
raise ServerAddon::MissingAddonError, "No extension with name #{name}"
end
addon.execute(request, params)
end

# Instantiate all server addons and store them in a hash for easy access after we have discovered the classes
Expand Down Expand Up @@ -298,9 +303,13 @@ def execute(request, params)
server_addon_name = params[:server_addon_name]
request_name = params[:request_name]

# Do not wrap this in error handlers. Server add-ons need to have the flexibility to choose if they want to
# include a response or not as part of error handling, so a blanket approach is not appropriate.
ServerAddon.delegate(server_addon_name, request_name, params.except(:request_name, :server_addon_name))
# Do not wrap this in additional error handlers. Server add-ons need to have the flexibility to choose if they want to
# include a response or not as part of their own error handling, so a blanket approach is not appropriate.
begin
ServerAddon.delegate(server_addon_name, request_name, params.except(:request_name, :server_addon_name))
rescue ServerAddon::MissingAddonError => e
send_error_response(e.message)
end
end
end

Expand Down