Open chipsenkbeil opened 2 years ago
@dtolnay What would you recommend?
To bring in a specific use case; some (most?) crond implementations support the use of EAGAIN
as an exit code to trigger a retry.
I am currently running into an issue with software where it would be incredibly useful to tag certain error types created with thiserror as being transient errors which can be retried and have the others be permanent errors.
A similar thing could be achieved by using Result<Termination>
as in the example provided by OP where I have another layer of main and wrap handle this in an elaborate match statement, but having this integrated in either anyhow would be nice, and it would be even better if it was implemented in a way that thiserror could integrate with.
With Rust 1.61.0 out, the
Termination
trait and associatedExitCode
are now stable. In the past, I maintained a large error enum purely to decipher what error code to return, printed out the error usingeprintln!
, and then exited withstd::process::exit
.Now, I'm thinking through a way for me to switch over to anyhow because it would streamline so much in my application, but I still need some way to keep track of what exit code to return for different errors. Looking for any advice/thoughts on how I could capture/encode that information when bubbling up errors.
Implement a wrapper type for
anyhow::Error
at the endOne way would be to create a newtype wrapper for the error and then use downcasting to figure out the underlying error with an associated exit code.
Derive an error type with an exit code
Some cleaner way?
Ideally, I'd love something like