Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

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

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

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

FauxFaux opened this issue Jun 20, 2017 · 0 comments

Comments

@FauxFaux
Copy link

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant