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

Allow the task failure message to be caught #3408

Closed
brson opened this issue Sep 7, 2012 · 13 comments
Closed

Allow the task failure message to be caught #3408

brson opened this issue Sep 7, 2012 · 13 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Milestone

Comments

@brson
Copy link
Contributor

brson commented Sep 7, 2012

I've occasionally wanted this (for example, it would enable better error reporting for ICEs) but haven't gotten around to implementing it. It should be quite easy now though. In core::rt::fail stash the value in TLS, then in the task cleanup code, pull it out of TLS and put it into the notification message. Modify task::try to return the string.

Ideally this will someday be an ~any type instead of ~str.

@brson
Copy link
Contributor Author

brson commented Sep 7, 2012

Oh, there is one failure path that doesn't go through core::rt::rt_fail - the out of stack failure. We'll have to account for that. Someday we'll need to also handle the out of stack failure from Rust code as well.

@bblum
Copy link
Contributor

bblum commented Sep 7, 2012

are there plans for bringing back the any type? exception handling is the only place i can think of where it would be useful.

the way sml does this is by having a global disjunctive exception ("extensible") type for which exception Name(args) at the top level will add a new arm, and anywhere you match on it you have to have a fallthrough case. not sure if this is what we'd want to do, but at least there's precedent.

@brson
Copy link
Contributor Author

brson commented Sep 7, 2012

There hasn't been any talk about any recently and we haven't had a pressing need for it. At this point I think it will likely just be implemented in the library.

I'd also like to use any for an imaginary RustScript language.

@bblum
Copy link
Contributor

bblum commented Sep 11, 2012

It would also be really nice if fail didn't have to allocate, especially if throwing an extensible exception type. Instead of shoving it through C++'s one-word-sized stack unwinding data, the fail wrapper function in libcore should probably just put it in TLS.

@bblum
Copy link
Contributor

bblum commented Sep 11, 2012

For lack of an any type, the best thing I can think of is a utility function that just uses a supervised task and a oneshot pipe internally: fn handle<T: send>(blk: fn(throw: fn(T) -> !)) -> Option<T>. Use it sort of like:

assert do handle |throw| {
    throw(some_val);
}.is_some();

Of course the built-in version would be better (more convenient, no memory allocation) and would only require T: owned instead of T: send.

(edit: if i am not mistaken, this is basically callcc.)

@bblum
Copy link
Contributor

bblum commented Sep 12, 2012

It occurs to me with an any type we could also support unboxing traits. (assuming the way to deal with any would be a type-level match.)

@pnkfelix
Copy link
Member

From the comments it seems like this issue has had an unfortunate bifurcation. There are two issues of interest:

  1. Adding the ability for task::try to catch and manipulate the value passed to fail!.
  2. Add an any type, which could be useful for exception handling code patterns, such as (1.).

The value passed to fail! is currently constrained to being a ~str, but that is (or at least should be) orthogonal to the description provided in (1).

I would prefer that the two topics be kept separate, especially since the meta-data on this issue (like "E-Easy") probably only applies if it is focused on (1) alone, and not (2) as well.

@pnkfelix
Copy link
Member

(Let's try to move future discussion of a potential any type to #61 perhaps?)

@brson
Copy link
Contributor Author

brson commented Jul 19, 2013

Related to #6874

@ghost ghost assigned catamorphism Oct 9, 2013
@catamorphism
Copy link
Contributor

I'm attempting to do this, as it would make rustpkg testing a lot easier.

@Kimundi
Copy link
Member

Kimundi commented Oct 10, 2013

@catamorphism I'm also looking into enabling this, but I'm still struggling with understanding how to pass the message along in the unwinding system.

I have a working implementation of a Any trait here: https://gist.github.com/Kimundi/6802198, and I'm trying a system where a failure cause is a enum of either a std::send_str::SendStr or a ~Any.

One thing I'm not sure how to handle is linked task failure, as that would mean sending a Sendable thing to multiple receivers at once. Maybe just have them receive a enum variant LinkedFailure or so.

Also, I still need to figure out how to adapt the Any trait to allow things like to_str() for the containing type without copying all code I have written for it.

Anyway, just wanted to pass my notes along.

@catamorphism
Copy link
Contributor

@Kimundi Ah ok. I'm not trying to be that ambitious -- just trying to make the ~str part of it work. A more general solution would be better, of course!

catamorphism added a commit to catamorphism/rust that referenced this issue Oct 12, 2013
When I started writing the rustpkg tests, task failure didn't set the
exit code properly. But bblum's work from July fixed that. Hooray! I
just didn't know about it till now.

So, now rustpkg uses exit codes in a more conventional way, and some of
the tests are simpler.

The bigger issue will be to make task failure propagate the error message.
Right now, rustpkg does most of the work in separate tasks, which means if
a task fails, rustpkg can't distinguish between different types of failure
(see rust-lang#3408)
bors added a commit that referenced this issue Oct 12, 2013
…hism,metajack

r? @metajack When I started writing the rustpkg tests, task failure didn't set the
exit code properly. But bblum's work from July fixed that. Hooray! I
just didn't know about it till now.

So, now rustpkg uses exit codes in a more conventional way, and some of
the tests are simpler.

The bigger issue will be to make task failure propagate the error message.
Right now, rustpkg does most of the work in separate tasks, which means if
a task fails, rustpkg can't distinguish between different types of failure
(see #3408)
@brson
Copy link
Contributor Author

brson commented Dec 21, 2013

This is done!

@brson brson closed this as completed Dec 21, 2013
bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
do not put tracking issue as part of the option's title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

5 participants