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

chain_err() shouldn't skip conversion (?) #159

Open
FauxFaux opened this Issue Jun 20, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@FauxFaux
Copy link

FauxFaux commented Jun 20, 2017

If you call a function in a library that returns a foriegn_links'd error, it gets converted into the appropriate type. However, if you chain_err(|| "library call"), the conversion is skipped.

That is, changing:

foo()?;

into:

foo().chain_err(|| "foo failed")?;

...changes the eventual error type from errors::Error { kind: Foo(FooError... to foo::FooError....

I dislike this behaviour: it makes matching on errors much more complicated (when rust-lang/rust#35943 gets fixed and we can match on errors). I believe the error should be converted into the appropriate wrapped type, and then chained. This is what would happen with various other places you could place the .chain_err() call.

Here's a full example: https://gist.github.com/FauxFaux/7a2889b9aa0cf2246e5bde5c7bc0b17f

The library call is line 7's john::useful(). Without line 8's .chain_err, this prints Destructured, John was guilty!. Inserting line 8 causes line 35's cast to fail, so it prints Destructuring failed:...

FauxFaux added a commit to FauxFaux/contentin that referenced this issue Jun 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.