Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error-handing notes #143

Open
bdarcus opened this issue Jan 13, 2024 · 0 comments
Open

Error-handing notes #143

bdarcus opened this issue Jan 13, 2024 · 0 comments

Comments

@bdarcus
Copy link
Owner

bdarcus commented Jan 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant