shepmaster / snafu

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

Comparison to anyhow #460

Open dhouck opened 3 months ago

dhouck commented 3 months 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 3 months 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 3 months 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.