Skip to content
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

ruby: Base error types? #11

Closed
casperisfine opened this issue Jan 18, 2022 · 7 comments · Fixed by #15
Closed

ruby: Base error types? #11

casperisfine opened this issue Jan 18, 2022 · 7 comments · Fixed by #15

Comments

@casperisfine
Copy link
Contributor

Currently the gem raise many different classes of errors, from what I gathered Trilogy#query can raise:

  • Errno::ETIMEDOUT on timeout
  • IOError when trying to use a closed connection.
  • Trilogy::Error for casting errors (and others?)

With database client it's generally very useful to have one base exception type that can be rescued, e.g. Redis::BaseConnectionError, otherwise it's too easy to forget one of the possible type of error on query.

Backward compatibility

To retain backward compatibility it would be possible to use modules, e.g.:

module Trilogy
   ConnectionErrors = Module.new

   class TimeoutError < Errno::ETIMEDOUT
     include ConnectionErrors
   end

   class ConnectionClosed < IOError
     include ConnectionErrors
   end

This would both allow to rescue all connection related errors with rescue Trilogy::ConnectionErrors while retaining compatibility with existing code using rescue Errno::ETIMEDOUT, IOError.

What do you think?

@matthewd
Copy link
Contributor

Yeah, I do like inheriting from the ruby core types where applicable, so the module approach sounds good to me.

What do you think of making Trilogy::Error itself a catch-all module for everything the gem can raise?

@casperisfine
Copy link
Contributor Author

What do you think of making Trilogy::Error itself a catch-all module for everything the gem can raise?

Would be great yes. For network clients l like to have a catch all like you suggest, then a base for everything "transcient" typically network issues, then another base for "invalid statements" type of errors.

If it's OK to change Trilogy::Error to be a module instead of a class, then I can do that.

@composerinteralia
Copy link
Contributor

composerinteralia commented Jan 18, 2022

Looks like GitHub does have some tests in a few places that do raise Trilogy::Error.new, but we should be able to change those to raise a more specific error.

Changing it from a class to a module may have implications for the version number the next time we release.

@casperisfine
Copy link
Contributor Author

Changing it from a class to a module may have implications for the version number the next time we release.

Yeah, an alternative is to have a Trilogy::Errors module alonside.

@matthewd
Copy link
Contributor

As long as it's still rescuable, I think it's probably fine? Technically even introducing and raising a subclass is an API change, but that seems like an over-constraint, especially right now while we can be pretty confident there are few downstreams to be potentially affected.

@casperisfine
Copy link
Contributor Author

Sounds good, I'll submit a PR tomorrow then.

@casperisfine
Copy link
Contributor Author

What do you think of making Trilogy::Error itself a catch-all module for everything the gem can raise?

So there's a bit of a problem with that one. Many errors are directly raised as Trilogy::Error directly from mysql error codes. So we'd need to distinguish between "client errors" and "server errors".

casperisfine pushed a commit to casperisfine/trilogy that referenced this issue Jan 19, 2022
Fix: trilogy-libraries#11

The goals are:

  - Not raise any error that isn't a descendant of `Trilogy::Error`.
  - Have a clear distinction between transient network errors that may be retried, and invalid queries that shouldn't.

Unsolved issues (yet)

  - Trilogy calls `rb_syserr_fail_str` in a few places. Meaning it can still raise any of the `Errno::*` errors.
  - `handle_trilogy_error` raise all `TRILOGY_ERR` as `ProtocolError` which is a `ConnectionError`, but
     I'm not certain none of the possible errors could be considered client errors.
adrianna-chang-shopify pushed a commit to casperisfine/trilogy that referenced this issue Dec 5, 2022
Fix: trilogy-libraries#11

The goals are:

  - Not raise any error that isn't a descendant of `Trilogy::Error`.
  - Have a clear distinction between transient network errors that may be retried, and invalid queries that shouldn't.

Unsolved issues (yet)

  - Trilogy calls `rb_syserr_fail_str` in a few places. Meaning it can still raise any of the `Errno::*` errors.
  - `handle_trilogy_error` raise all `TRILOGY_ERR` as `ProtocolError` which is a `ConnectionError`, but
     I'm not certain none of the possible errors could be considered client errors.
adrianna-chang-shopify pushed a commit to casperisfine/trilogy that referenced this issue Dec 6, 2022
Fix: trilogy-libraries#11

The goals are:

  - Not raise any error that isn't a descendant of `Trilogy::Error`.
  - Have a clear distinction between transient network errors that may be retried, and invalid queries that shouldn't.

Unsolved issues (yet)

  - Trilogy calls `rb_syserr_fail_str` in a few places. Meaning it can still raise any of the `Errno::*` errors.
  - `handle_trilogy_error` raise all `TRILOGY_ERR` as `ProtocolError` which is a `ConnectionError`, but
     I'm not certain none of the possible errors could be considered client errors.
adrianna-chang-shopify pushed a commit to casperisfine/trilogy that referenced this issue Jan 11, 2023
Fix: trilogy-libraries#11

The goals are:

  - Not raise any error that isn't a descendant of `Trilogy::Error`.
  - Have a clear distinction between transient network errors that may be retried, and invalid queries that shouldn't.

Unsolved issues (yet)

  - Trilogy calls `rb_syserr_fail_str` in a few places. Meaning it can still raise any of the `Errno::*` errors.
  - `handle_trilogy_error` raise all `TRILOGY_ERR` as `ProtocolError` which is a `ConnectionError`, but
     I'm not certain none of the possible errors could be considered client errors.
adrianna-chang-shopify pushed a commit to casperisfine/trilogy that referenced this issue Jan 11, 2023
Fix: trilogy-libraries#11

The goals are:

  - Not raise any error that isn't a descendant of `Trilogy::Error`.
  - Have a clear distinction between transient network errors that may be retried, and invalid queries that shouldn't.

Unsolved issues (yet)

  - Trilogy calls `rb_syserr_fail_str` in a few places. Meaning it can still raise any of the `Errno::*` errors.
  - `handle_trilogy_error` raise all `TRILOGY_ERR` as `ProtocolError` which is a `ConnectionError`, but
     I'm not certain none of the possible errors could be considered client errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants