Idiomatic error handling and error chaining

hey guys, I just found error-chain
is that the go-to library these days for errors?
any recommendations/opinions for/against?

Generally I recommend anyhow for applications and thiserror for libraries.

1 Like

Please start a new topic if you have a new question - your issue doesn't look related to this thread.

brother thanks for your guidance i have started a new thread if you can help me to resolve this issue it would be really beneficiary for me. thanks in advance

Thanks a lot. I did not know them. It feels like there is a room to improve ergonomics of error handling in the standard library :thinking:

I'm just starting to get back into Rust after a 2--3 years away so my experience with the current state of the ecosystem is limited. (i.e. take what I say with a grain of salt.) That said, I have some experience from the past about how Rust and its ecosystem evolves:

I'd personally stick with anyhow. error-chain is ancient and anyhow seems not only significantly superior but also much more future proof.

Additionally. There seems to be several somewhat busy issues and RFCs and experimental API's already merged to nightly about more features and ergonomics for errors in std and core. So there's definitely hope for future improvement. However, don't get too excited. My experience is changes can take years to make it to stable for various (good) reasons. Also, don't be worried that anyhow might be incompatible with any future design of std::Error. In my experience the way new functionality in std/core/rustc always goes is that the people working on the crates and those working on std/core/rustc work together to ensure compatibility.

I stumbled across this fantastic Blog post.
It has a good history of error handling strategies and libraries and how they've developed, starting with error-chain in 2016.
From reading that, I agree that anyhow or thiserror are the way to go. That's not to say that error-chain or failure or other older libraries are bad. It's just that new libraries have built on and refined their ideas. At times std has also taken onboard their ideas and changed the std::error::Error trait.

We're all standing on the shoulders of giants :slight_smile:

1 Like

I also found this awesome blog post. It has the same idea with yoshua wuyts's blog post. I agree with their ideas and I think it's the best approach to handling error in rust for now.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.