Skip to content

Instantly share code, notes, and snippets.

@loverdos
Created June 15, 2024 16:44
Show Gist options
  • Save loverdos/80914d644e37b16cbf95c27afeff698f to your computer and use it in GitHub Desktop.
Save loverdos/80914d644e37b16cbf95c27afeff698f to your computer and use it in GitHub Desktop.
// 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