error-chain
error-chain copied to clipboard
chain_err() shouldn't skip conversion (?)
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 https://github.com/rust-lang/rust/issues/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:...