shepmaster / snafu

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

Comparison to anyhow #460

Open dhouck opened 1 month ago

dhouck commented 1 month ago

Like with #321, the Comparison page seems incomplete without a comparison between SNAFU and Anyhow. As far as I can tell the Whatever type in SNAFU is very similar to an Anyhow error, but I donʼt know enough about the details of either one to write a good comparison myself.

Enet4 commented 1 month ago

I wrote a piece about migrating a software project to SNAFU some years ago. Some of the parts are outdated, but the concept of anyhow relying on a dynamic error type still holds.

anyhow and eyre are mostly designed for applications, as they facilitate the aggregation of multiple error types into a single source of information about the error. This error can be expanded across the program stack via the extended context operator, hence gaining additional information. They deliberately employ a "kitchen-sink" error type, which is more complicated to take part in code flow if necessary. When it comes to libraries, structured error types are usually preferred.

dhouck commented 1 month ago

I definitely prefer structure types in a lot of cases, but since snafu has Whatever also, it seems worth doing direct comparisons with that.