|
|
|
|
|
by icambron
1319 days ago
|
|
The binary vs library thing seems like an oversimplification to me. I think it's more like: do you need callers to handle this error specifically? With a library the answer is "I don't know, better let them do it", so you don't want anyhow. But in a binary, you may or may not, and it depends on the error. The pattern I use in my app is to use thiserror, and then just have an anyhow catch-all. That lets me do specific stuff where I know I'm going to need specific handling, and an easy-to-use fallback for just saying "this bad thing happened" with the anyhow! macro. #[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Not logged in")]
NotLoggedIn,
#[error(transparent)]
Api(#[from] ApiError),
// etc
#[error(transparent)]
Other(#[from] anyhow::Error),
}
I don't know if this is the best pattern but it's worked really well for me. |
|