News for hackers. Stuff that matters.
Re:Guide to Error Handling in Rust by shepmaster on Sunday August 25, 2024 @11:14AM (#41347865)
The biggest thing to me is that many people lump errors by type (“all IO errors are equivalent”) which is very wrong to me. SNAFU encourages and streamlines bucketing your errors into detailed chunks.

Along the way, it makes adding details to your error easier (automatic calls to Into without a closure; optional implicit details).

It combines string-like errors (anyhow) and structured errors (thiserror) in one library.

It has basic command line error formatting that shows the causal chain without duplication.

I don’t use eyre so I don’t feel comfortable comparing to it.

Re:Guide to Error Handling in Rust by xvedejas on Sunday August 25, 2024 @03:34PM (#41350525)
Is there a way snafu could be redesigned not to rename Error to Snafu in custom error variants? It's annoying for like IDE reasons, but maybe technically challenging to fix.
Re:Guide to Error Handling in Rust by shepmaster on Sunday August 25, 2024 @06:57PM (#41352252)
I think you are asking for this config [0] (let me know if not, maybe provide an example), but I’d caution against renaming it back to “Error”. The context selectors are not themselves errors, they are more-or-less fancy error constructors. It’s the same logic I’d use to call it `Error::new` instead of `Error::error`.

Having the context selectors called the exact same as the variants was the way the original version of SNAFU worked, but it was also the number one cause of confusion and support requests.

[0]: https://docs.rs/snafu/latest/snafu/derive.Snafu.html#changin...