Skip to content

Commit

Permalink
Group incomplete and empty message into MessageError (#515)
Browse files Browse the repository at this point in the history
We're sometimes hitting `EmptyMessageError` in certain cases after the changes in #498. We only rescue `IncompleteMessageError`, which then makes it look like the add-on is crashing.

Let's group the two errors under a common ancestor, so that we can rescue all types of message errors where needed.
  • Loading branch information
vinistock authored Nov 6, 2024
1 parent 3e7e3f5 commit 1a9f344
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/ruby_lsp/ruby_lsp_rails/runner_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def create_client(outgoing_queue)
end

class InitializationError < StandardError; end
class IncompleteMessageError < StandardError; end
class EmptyMessageError < StandardError; end
class MessageError < StandardError; end
class IncompleteMessageError < MessageError; end
class EmptyMessageError < MessageError; end

extend T::Sig

Expand Down Expand Up @@ -115,7 +116,7 @@ def initialize(outgoing_queue)
sig { params(server_addon_path: String).void }
def register_server_addon(server_addon_path)
send_notification("server_addon/register", server_addon_path: server_addon_path)
rescue IncompleteMessageError
rescue MessageError
log_message(
"Ruby LSP Rails failed to register server addon #{server_addon_path}",
type: RubyLsp::Constant::MessageType::ERROR,
Expand All @@ -126,7 +127,7 @@ def register_server_addon(server_addon_path)
sig { params(name: String).returns(T.nilable(T::Hash[Symbol, T.untyped])) }
def model(name)
make_request("model", name: name)
rescue IncompleteMessageError
rescue MessageError
log_message(
"Ruby LSP Rails failed to get model information",
type: RubyLsp::Constant::MessageType::ERROR,
Expand All @@ -146,7 +147,7 @@ def association_target_location(model_name:, association_name:)
model_name: model_name,
association_name: association_name,
)
rescue IncompleteMessageError
rescue MessageError
log_message(
"Ruby LSP Rails failed to get association location",
type: RubyLsp::Constant::MessageType::ERROR,
Expand All @@ -157,7 +158,7 @@ def association_target_location(model_name:, association_name:)
sig { params(name: String).returns(T.nilable(T::Hash[Symbol, T.untyped])) }
def route_location(name)
make_request("route_location", name: name)
rescue IncompleteMessageError
rescue MessageError
log_message(
"Ruby LSP Rails failed to get route location",
type: RubyLsp::Constant::MessageType::ERROR,
Expand All @@ -168,7 +169,7 @@ def route_location(name)
sig { params(controller: String, action: String).returns(T.nilable(T::Hash[Symbol, T.untyped])) }
def route(controller:, action:)
make_request("route_info", controller: controller, action: action)
rescue IncompleteMessageError
rescue MessageError
log_message(
"Ruby LSP Rails failed to get route information",
type: RubyLsp::Constant::MessageType::ERROR,
Expand All @@ -191,7 +192,7 @@ def delegate_notification(server_addon_name:, request_name:, **params)
def pending_migrations_message
response = make_request("pending_migrations_message")
response[:pending_migrations_message] if response
rescue IncompleteMessageError
rescue MessageError
log_message(
"Ruby LSP Rails failed when checking for pending migrations",
type: RubyLsp::Constant::MessageType::ERROR,
Expand All @@ -202,7 +203,7 @@ def pending_migrations_message
sig { returns(T.nilable(T::Hash[Symbol, T.untyped])) }
def run_migrations
make_request("run_migrations")
rescue IncompleteMessageError
rescue MessageError
log_message(
"Ruby LSP Rails failed to run migrations",
type: RubyLsp::Constant::MessageType::ERROR,
Expand All @@ -225,15 +226,15 @@ def delegate_request(server_addon_name:, request_name:, **params)
request_name: request_name,
**params,
)
rescue IncompleteMessageError
rescue MessageError
nil
end

sig { void }
def trigger_reload
log_message("Reloading Rails application")
send_notification("reload")
rescue IncompleteMessageError
rescue MessageError
log_message(
"Ruby LSP Rails failed to trigger reload",
type: RubyLsp::Constant::MessageType::ERROR,
Expand Down

0 comments on commit 1a9f344

Please sign in to comment.