Skip to content

Improved Ruby error classes #113

@jhawthorn

Description

@jhawthorn

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:

  • QueryError is our default fallback error class. I don't think this makes any sense, as this is a ProtocolError subclass but all errors other than TRILOGY_ERR are IMO connection-level errors. I think we should make 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_CLOSED_CONNECTION". This error represents essentially an EOF over our socket, and it's one of the more common errors we come across. It's also the error we'll see if we attempt communication after a trilogy_sock_shutdown. Currently this appears as QueryError: 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 from ConnectionClosed, which is only raised from an explicitly closed connection. How about Trilogy::EOFError? For backwards compatibility I'd probably include "TRILOGY_CLOSED_CONNECTION" in the string.
    • Another possibility I'd like to entertain is deleting the translation of EPIPE errors to TRILOGY_CLOSED_CONNECTION, which would break compatibility with those doing string matching but I think otherwise is just better and more accurate information.
  • SyscallError vs ConnectionError. As raised in Handle EADDRNOTAVAIL as a BaseConnectionError instead of SyscallError #98, there's some confusion between SyscallError and BaseConnectionError. One option is that we can make Trilogy::SyscallError inherit from ConnectionError 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).
  • I think 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 previous DatabaseError naming but am open to other options. How about ServerError "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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions