bdarcus / csln

Reimagining CSL
Mozilla Public License 2.0
12 stars 0 forks source link

Error-handing notes #143

Open bdarcus opened 5 months ago

bdarcus commented 5 months ago

I want to avoid using unwrap or expect in really any of the code, aside from maybe the tests.

I likely want to write my own error types, using anyhow (for the cli only) or thiserror (for everything else; though burnsushi recommends against it).

... if one is building a library intended for others to use, I’d suggest writing out concrete error types and providing an appropriate std::fmt::Display impl.

This post suggests using the former in development, and only replacing once things are mostly done.

https://blog.burntsushi.net/unwrap/ https://www.lpalmieri.com/posts/error-handling-rust/#anyhow-or-thiserror

In the post above burnsushi argues against linting unwrap and/or expect, though in #132 I currently am.

Examples

Zola uses anyhow, but basically aliases it, perhaps so it is easier to change later?

https://github.com/getzola/zola/blob/9fe455892e850da0684817ae9553e61757d9e5e4/components/utils/src/fs.rs#L9

See citationberg for examples of custom error types.