Comment by echelon
10 years ago
You definitely need to use the `From` trait if you haven't already. I know others have already recommended this, but it cannot be encouraged enough. It's a great pattern for idiomatic error handling--much better than matching or `map_err`.
Maybe you already know this, but if not (and for others that don't), try it immediately. You'll be glad you did.
I know this and I don't like this. Every level of abstraction should have own errors, without dependencies on some other errors, otherwise code will be too fragile. And it's not theoretical assumption, but lessons from practice.
It's not clear why you think that From/map_err don't let you separate errors at levels of abstractions. It gets done all the time.
And error-chain exists if you want a more fluid system of errors.
And if you don't trust me in this question, you can try to read Uncle Bob. I thought it's not applicable to Rust (because initially it was about OOP), but on one of refactorings I got a lot of broken dependencies in From trait. Then I realized good rules worth to be remembered.