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 upRFC: error interoperation #201
Conversation
This was referenced Aug 15, 2014
This comment has been minimized.
This comment has been minimized.
reem
commented
Aug 15, 2014
|
After some discussion on IRC @aturon suggested I link to my efforts on this here. Link: https://github.com/reem/rust-error It is at least partially inspired by some ideas from this RFC, but provides an interface that allows third-party errors the same interface as first-party errors, which a plain enum can't do. I came up with this abstraction while trying to create an abstract error type for Iron, which has rather demanding constraints. |
This comment has been minimized.
This comment has been minimized.
|
I didn't have time to do more than a brief skimming of this, and while I'm generally in favor of the motivation of this RFC, I'm worried that this makes |
This comment has been minimized.
This comment has been minimized.
|
As a data point, cargo has been using a strategy similar to this for quite some time now, and it's been working out marvelously. |
This comment has been minimized.
This comment has been minimized.
|
I'm a huge fan of something like this proposal. Composability of APIs is very important and currently the different error types make for a very hard API. I do not mind losing the ability to have non error things in |
This comment has been minimized.
This comment has been minimized.
|
@kballard That's a good point. I actually think the two part of this proposal -- the |
This comment has been minimized.
This comment has been minimized.
reem
commented
Aug 18, 2014
|
My main issue with this RFC is that this error type does not provide a good way to handle errors. The Error trait makes reporting and propagating errors very nice, but when I receive a I think this is definitely a large step in the right direction, but much more thought needs to be put in to providing a good way to not only safely propagate and mix errors across library boundaries, but to also handle errors across library boundaries. This is a hard problem, but it's one Rust absolutely must solve if we don't want returning |
This comment has been minimized.
This comment has been minimized.
nielsle
commented
Aug 19, 2014
|
This looks nice. I like the idea of separating pub trait Error{}
impl<E: Error> FromError<E> for E { ... }
#[deriving(Error)]
struct MyError { ... }BTW: When running the code example in the RFC i seem to get an error http://is.gd/lHcbR2
|
This comment has been minimized.
This comment has been minimized.
reem
commented
Aug 19, 2014
|
@nielsle This proposal relies on multi-dispatch, which is added in a different RFC. |
This comment has been minimized.
This comment has been minimized.
|
@aturon Splitting I feel like the only real solution to this issue is to have two macros, one that is the current |
This comment has been minimized.
This comment has been minimized.
|
@kballard Sorry, I think I was unclear. If we decouple the two mechanisms, we can write: impl<E> FromError<E> for E {
fn from_err(err: E) -> E {
err
}
}which, with multidispatch, will still allow you to define other impls when actually converting between error types. This would allow the revised |
glaebhoerl
referenced this pull request
Aug 22, 2014
Closed
RFC: error conventions and syntactic support (including changes to macro syntax) #204
This comment has been minimized.
This comment has been minimized.
|
Note: I've revised the RFC to decouple |
This comment has been minimized.
This comment has been minimized.
reem
commented
Aug 27, 2014
|
@aturon Have you considered adding Any-like methods to This kind of functionality is important because there are situations, like in Iron, where you want to express "this should be a generic error handler" but you want that handler to actually be able to handle and introspect errors to a higher degree than just checking their name. |
This comment has been minimized.
This comment has been minimized.
|
@reem Yes, in fact I just pushed another update to bound |
This comment has been minimized.
This comment has been minimized.
reem
commented
Aug 27, 2014
|
Unfortunately, because of the way Any works right now, a bit more effort is needed (at minimum, AnyRefExt needs to be implemented for both |
This comment has been minimized.
This comment has been minimized.
|
@reem You're right, my proposal relies on being able to upcast trait objects in general, which is something we intend to be possible but are still working on. Until that lands, we'll probably need a workaround along the lines you're suggesting. I'll revise the RFC accordingly. |
This comment has been minimized.
This comment has been minimized.
reem
commented
Aug 28, 2014
|
@aturon An additional workaround I've found necessary is to make all the uses of Basically |
This comment has been minimized.
This comment has been minimized.
|
I believe that it is planned such that |
alexcrichton
assigned
aturon
Sep 4, 2014
alexcrichton
force-pushed the
rust-lang:master
branch
from
6357402
to
e0acdf4
Sep 11, 2014
aturon
referenced this pull request
Sep 16, 2014
Merged
First-class error handling with `?` and `catch` #243
aturon
force-pushed the
rust-lang:master
branch
from
4c0bebf
to
b1d1bfd
Sep 16, 2014
This comment has been minimized.
This comment has been minimized.
reem
commented
Sep 16, 2014
|
@alexcrichton Is there an issue I can track for that? |
This comment has been minimized.
This comment has been minimized.
|
@aturon I think this might be related/referring to the fact that Re: previous comment, I had been under the impression that using |
This comment has been minimized.
This comment has been minimized.
ghost
commented
Oct 6, 2014
|
I feel the stack of error messages shouldn't be part of the function signatures if we don't have enough type system to do it right. We could maintain a task-local error queue for example. |
This comment has been minimized.
This comment has been minimized.
But not for vtable purposes! Which is, of course, the only time you want |
This comment has been minimized.
This comment has been minimized.
|
@glaebhoerl Also, that discussion you linked is fascinating. You've basically shown that, as things stand, we can trivially violate parametricity for generics. I will definitely make sure the rest of the team is aware of this. |
This comment has been minimized.
This comment has been minimized.
reem
commented
Oct 7, 2014
|
@aturon I currently support Iron's error functionality in a library and wouldn't be strongly opposed to continuing to do so with a This could be accomplished downstream with something like: pub struct Lifted<E> where E: Error + Any {
underlying: E
}
pub trait DynamicError: Error + Any {
fn lift<E: Error + Any>(e: E) -> Box<DynamicError> {
box Lifted { underlying: e }
}
}
impl<E> DynamicError for Lifted<E> where E: Error + Any {}
impl Error for Box<DynamicError> { ... }with only one major problem I see: without either If the above was solved, then everything would be fine. |
This comment has been minimized.
This comment has been minimized.
|
@reem I'm not sure I understand the worry at the end of your comment. If you The main downside to this over baking in |
This comment has been minimized.
This comment has been minimized.
|
Just some food for thought: It would be awesome if this could be the start for making wrapping for results on return implicit. Imagine there was a Old and boring: fn foo(x: bool) -> Result<int, MyError> {
if (x) {
let _ : () = try!(do_something())
}
Ok(42)
}New and fancy: fn foo(x: bool) -> Result<int, MyError> {
if (x) {
try!(do_something())
}
42
} |
This comment has been minimized.
This comment has been minimized.
|
@mitsuhiko That is essentially part of #243 in this form:
(I believe this is necessary, as opposed to |
This comment has been minimized.
This comment has been minimized.
reem
commented
Oct 15, 2014
|
@aturon Ya, with sufficient code duplication I think it's possible to create a general |
aturon commentedAug 15, 2014
This RFC improves interoperation between APIs with different error
types. It proposes to:
try!macro for clients of multiplelibraries with disparate error types.
by introducing an
Errortrait.The proposed changes are all library changes; no language changes are
needed -- except that this proposal depends on
multidispatch happening.
Rendered