Created
June 15, 2024 16:44
-
-
Save loverdos/80914d644e37b16cbf95c27afeff698f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tokio = { version = "1", features = ["full"] } | |
// tracing = "0.1.40" | |
// tracing-subscriber = "0.3.18" | |
// snafu = "0.8.3" | |
// exitcode = "1.1.2" | |
use tracing::{error as log_error}; | |
use snafu::Report; | |
use tracing_subscriber; | |
async fn main_result() -> Result<()> { Ok(()) } | |
#[tokio::main] | |
async fn main() { | |
tracing_subscriber::fmt::init(); | |
if let Some(error) = main_result().await.err() { | |
log_error!("{}", error); | |
let report = snafu::Report::from_error(&error); | |
eprintln!("{}", report); | |
let exit_code = | |
match error { | |
MyError::Error1 => { exitcode::UNAVAILABLE } | |
// ... | |
}; | |
exit(exit_code); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment