-
Notifications
You must be signed in to change notification settings - Fork 72
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
Improved Ruby error classes #113
Comments
I think the key thing to consider when designing error hierarchies, is the use case. Which errors do users need to rescue? For network libraries my answer is generally that errors fall in two main groups:
You can then subclass this as much as you want for readability. |
This makes sense to me 👍 Also makes treating all the syscall errors as connection errors easy to reason about.
Definitely agree that this shouldn't be a
What are you thinking instead @jhawthorn ? Just let it bubble up as a syscall error?
I think it's fair to treat all of the errno errors as connection errors. Seems like most of the ones consumers would actually encounter would be connection errors. That gets us around the headache of trying to figure out which ones we should classify as conn errors versus not, and I think, as the issue opened around EADDRNOTAVAIL demonstrates, it's confusing to users to have to rescue these as separate error classes.
Yeah, might as well just revert back to |
I entirely agree with the opinions shared here 💯 .
specifically about this usecase, IMO |
The thing that jumps into my head here is something like (But that's just a passing thought, and even if we did think it's more descriptive, I'm doubtful it's worth the rename effort to change; I agree that I don't like that Agree not- Also agree that I've misread One idea I had was that we could consciously deviate from the "FooError" pattern as a gentle nudge that we're [using an exception as a means of] communicating an error from elsewhere, rather than directly reporting a "local" error up the stack: |
In support of our rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::ECONNRESET => error
raise ActiveRecord::ConnectionNotEstablished.new(error.message) |
I learned I was wrong about this. |
cc @adrianna-chang-shopify @casperisfine @composerinteralia @dhruvCW @matthewd
We made some improvements to the Ruby extension's error classes recently but based on recent discussions I think still have a way to go. I wanted to gather opinions in this issue and am happy to implement what we can come to a consensus on.
Problems I see:
BaseConnectionError
the default error class for things which haven't been given a specific meaning (alternatively we could exhaustively define error classes for all trilogy status codes).trilogy_sock_shutdown
. Currently this appears asQueryError: TRILOGY_CLOSED_CONNECTION
and we're forced to do string matching to detect it. I think this deserves its own error class, but also it should probably be distinct fromConnectionClosed
, which is only raised from an explicitly closed connection. How aboutTrilogy::EOFError
? For backwards compatibility I'd probably include "TRILOGY_CLOSED_CONNECTION" in the string.TRILOGY_CLOSED_CONNECTION
, which would break compatibility with those doing string matching but I think otherwise is just better and more accurate information.Trilogy::SyscallError
inherit fromConnectionError
and then have only one thing to rescue, or we could better document that users should rescue both classes (I don't feel very strongly either way).ProtocolError
's name is confusing. I read this as "protocol violation" rather than "we were told over the protocol that an error occurred", and I've seen confusion from others about the same. I preferred the previousDatabaseError
naming but am open to other options. How aboutServerError
"an error reported by the server"? Whatever we choose we can make the classes aliases of each other, so there should be minimal compatibility problems.The text was updated successfully, but these errors were encountered: