-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Refactor error types #936
Comments
Musings on how to implement thisWe could use quick-error, a macro crate that will reduce much of the overhead our error code currently has. This will also make it feasible to add more specialized error variants to parts of diesel. But why stop with syntactic? The error_chain crate is quick-error on steroids and has become sort of a standard for many. It offers a lot of what we want, incl. nice macros for generating error types and early returns, converting strings to errors ad-hoc (nice for development), and backtraces (when A way around that might be to write an opaque error type ourselves that implements Error but little else, and use error-chain internally. I'm not sure how much overhead that introduces when dealing with an error, but the opaque struct could be pointer-sized ( |
This might also be a good chance to refactor our code style to return errors: error-chain has two nice macros, |
Maybe someone should rise concerns here about the none breaking extensibility of the ErrorKind field? |
I recently just had the exercise in the reqwest crate. I also considered error_chain, but only briefly. I considering a public facing enum to be the wrong design, because it's impossible to add new variants, and it exposes the exact representation of how you store the errors. For reference, here's the reqwest error: https://github.com/seanmonstar/reqwest/blob/master/src/error.rs |
We do add a |
Yea, and while shame on anyone actually matching on such a variant, it is possible, and it would break crates or apps that did it when you add a new variant. However, enum fields are all public, so if you were to, say, decide to stop storing some errors as boxes and instead of the normal values, you can't do so with a public enum. You could if it were in a private struct field. |
In the future, there might be rust-lang/rfcs#2008 which would fix this problem |
|
Update: Seems like people are actively working on |
I've spent most of the day working on this, and after coming at it from 3 different angles -- I don't think this is a good change. Basically the benefits of using
That comes at several costs though:
Ultimately I don't think either of the benefits get us very much. As I mentioned, the places where the "chain" is useful are places that are uncommon, and we could achieve the same thing by implementing I think we're also over-estimating the value of the backtrace. Ultimately for our users, the only valuable piece of the backtrace will be where the query was executed. They can easily get that by using So given all of that, I'm going to close this in favor of just implementing |
Currently, we have an enum with a bunch of error variants, most of which are actually just
Box<Error>
(see 0.13 docs). I think we can do this in a nicer way.Requirements
The text was updated successfully, but these errors were encountered: