Skip to content

Commit

Permalink
Improve error handling for database problems
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Nov 7, 2024
1 parent 4f72ce4 commit 44cf6a1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/ruby_lsp/ruby_lsp_rails/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def send_message(message)
# Log a message to the editor's output panel
def log_message(message)
$stderr.puts(message)
send_message({ result: nil })
end
end

Expand Down Expand Up @@ -103,6 +104,9 @@ def start
end

def execute(request, params)
request_name = request
request_name = "#{params[:server_addon_name]}##{params[:request_name]}" if request == "server_addon/delegate"

case request
when "shutdown"
@running = false
Expand All @@ -128,11 +132,11 @@ def execute(request, params)
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 ActiveRecord::NoDatabaseError
log_message("Request #{request_name} failed because the database does not exist.")
rescue => e
log_message("Request #{request_name} failed:\n" + e.full_message(highlight: false))
end
Expand Down

0 comments on commit 44cf6a1

Please sign in to comment.