-
Notifications
You must be signed in to change notification settings - Fork 9
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
Flatten error handling, reducing generics #54
Conversation
See: oxidecomputer/omicron#4210 for usage |
General question, is returning a |
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.
Looks good other than the question about whether we want to return our own type for future expandability.
Can I dig into what you're suggesting here? I don't necessarily disagree, but I want to get a better idea of "costs, pros, and cons". It wasn't a simple "wrapper" newtype, but this is kinda what the enum ConnectionError {
Database(DieselError),
Connection(WeFailedToPollTheConnectionPool),
} Arguably we could have had additional layers, other errors here, etc... but this was painful from an ergonomics point-of-view, because most of the time when someone issues a request to the DB, error-handling is specific to "what did the DB say", meaning that callers want to match on the We could add a wrapper type like: enum AsyncBb8DieselError(DieselError); But I dunno how advantageous that would be over just returning the type directly, since clients need to match on / decompose that |
I do agree that this is a huge improvement over the current situation -- mixing connection and database errors doesn't seem quite right for the reasons you pointed out. What about: struct AsyncBb8DieselError {
error: DieselError,
// ... some extra fields, e.g. identifier for the connection in the pool} I'm wondering if issues like #47 would have been ever so slightly easier to spot with that extra info. But I certainly won't block on this. |
Ah, that makes sense. If we were sticking with async-bb8-diesel forever, I'd be strongly in favor of this direction. I will throw out one more caveat -- this whole crate pre-dated With this in mind, I think I'm going to move forward on this PR as-is, but I really do like the proposal of "struct as a wrapper around an underlying error + easy access to underlying error, but extra auxiliary error info which can be propagated back up" too. |
Depends on oxidecomputer/async-bb8-diesel#54 As of #4140 , we check out connections before issuing queries to the underlying database. This means that when we receive errors from the database, they are not overloaded as "connection checkout" OR "database" errors - they are now always database errors.
This is a clean-up enabled by #52
ConnErr
generic variantdiesel
error type, rather than a "connection variant". The old variant was used to encapsulate either "a database error" or "a checkout error". Since callers now must checkout connections before issuing queries, these don't need to be intermingled.