shepmaster / snafu

Easily assign underlying errors into domain-specific errors while adding context
https://docs.rs/snafu/
Apache License 2.0
1.45k stars 61 forks source link

Comparison to thiserror #321

Open Person-93 opened 2 years ago

Person-93 commented 2 years ago

Hi,

I stumbled across this project today and it looks really cool. I was really happy to see a comparison section in the guide, but I was hoping to see how it compares to thiserror.

I found this thread on reddit, but it's from two years ago so I'm not sure how relevant it is.

I found this discussion from the kube-rs project that looks like it might be more up to date.

Would you consider adding an official section to the guide for this? If you share your thoughts with me, I'd be happy to help draft it.

shepmaster commented 2 years ago

I would love to have a comparison section vs thiserror. My biggest worry is that I don't want to mischaracterize another crate, and I haven't used thiserror extensively enough to feel comfortable knowing what it can and can not do.

Do you have experience with thiserror? If so, maybe you can suggest some of the points that you like about it and I can correlate with equivalent SNAFU features.

To me, the ability to succinctly add additional data is the big thing that SNAFU brings here:

something_that_can_fail().context(FailedToDoSomething { extra, data })?;

This also corresponds to the fact that you can easily categorize one underlying error type into multiple higher-level errors:

some_operation().context(FailedToDoThingOne)?;
some_operation().context(FailedToDoThingTwo)?;

This is especially useful with how many crates have one big error type for every possible failure that could ever occur (e.g. std::io::Error, reqwest::Error).

Person-93 commented 2 years ago

Here are a couple things that come to mind. I'll try to add more later as I think of them.