Migrate from using anyhow::Error in all places with .context(error message) to instead create a dedicated #[derive(Error)] enum Error type.
- We should use the
thiserrors crate to make it easy to associate custom error messages to each enum variant.
- That enum could still contain an
#[error(transparent)] Internal(#[from] anyhow::Error) variant to handle errors from external library calls that we don't handle specifically
fn main() could then check the error returned by match cli.command { … } and handle pretty-printing the error if it's one of ours (i.e. ensure we avoid the stacktrace-style scary output and only print a simple but clear unique error message, maybe in red) and fallback to regular stacktrace-like output for the Internal(anyhow::Error) variant.
Migrate from using
anyhow::Errorin all places with.context(error message)to instead create a dedicated#[derive(Error)] enum Errortype.thiserrorscrate to make it easy to associate custom error messages to each enum variant.#[error(transparent)] Internal(#[from] anyhow::Error)variant to handle errors from external library calls that we don't handle specificallyfn main()could then check the error returned bymatch cli.command { … }and handle pretty-printing the error if it's one of ours (i.e. ensure we avoid the stacktrace-style scary output and only print a simple but clear unique error message, maybe in red) and fallback to regular stacktrace-like output for theInternal(anyhow::Error)variant.