-
Notifications
You must be signed in to change notification settings - Fork 28
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
Improve error handling for database problems #517
Improve error handling for database problems #517
Conversation
271cf38
to
44cf6a1
Compare
@@ -103,6 +104,9 @@ def start | |||
end | |||
|
|||
def execute(request, params) | |||
request_name = request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was in the wrong place previously.
Looking into adding tests for this. |
44cf6a1
to
df0c0c1
Compare
Added tests. |
Thanks for the quick turnaround! Really appreciated 🙇♂️ |
@@ -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 }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed the right solution as we need to return something even when errors occur. But this is not the right place to put it.
The goal of the log_message
method is to allow both the server and its add-ons to send debug messages to the output tab, even if disconnected from providing a result.
If a database error was to occur in a notification, where no response is expected, then we'd be writing a nil result to the pipe, which wouldn't be read by the notification. The next request would then incorrectly read it and we'd end up with the request/response cycle out of sync.
We need to move this line to where error handling happens, so that log_message
is not coupled with returning responses to the editor. And this result can only be returned when rescuing errors for requests - not for notifications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I wasn't considering usage from add-ons.
Closes #516
This change allows Ruby LSP to stay alive even if an error occurred when trying to connect to the database.
I also added a specific
rescue
forActiveRecord::NoDatabaseError
since this could be a common problem. Without that, users would see a very long stacktrace in the logs.It may partially help with #521 too.