Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRefactor error types #936
Comments
killercup
added
the
breaking change
label
Jun 6, 2017
This comment has been minimized.
This comment has been minimized.
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 ( |
killercup
added this to the 1.0 milestone
Jun 6, 2017
This comment has been minimized.
This comment has been minimized.
|
This might also be a good chance to refactor our code style to return errors: error-chain has two nice macros, |
This comment has been minimized.
This comment has been minimized.
|
Maybe someone should rise concerns here about the none breaking extensibility of the ErrorKind field? |
This comment has been minimized.
This comment has been minimized.
seanmonstar
commented
Jun 8, 2017
|
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 |
This comment has been minimized.
This comment has been minimized.
|
We do add a |
This comment has been minimized.
This comment has been minimized.
seanmonstar
commented
Jun 8, 2017
|
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. |
This comment has been minimized.
This comment has been minimized.
|
In the future, there might be rust-lang/rfcs#2008 which would fix this problem |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Update: Seems like people are actively working on |
This comment has been minimized.
This comment has been minimized.
|
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 |
killercup commentedJun 6, 2017
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