From b7b1f7e41515ab18dd3860b79acb3781a50dd116 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Wed, 29 May 2024 22:45:07 +0300 Subject: [PATCH] chore: Create `try_main` to print the error message Signed-off-by: Awiteb --- src/main.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index ac5902c..40cfa7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ #![doc = include_str!("../README.md")] -use std::{env, fs, sync::Mutex}; +use std::{env, fs, process::ExitCode, sync::Mutex}; use lazy_static::lazy_static; use salvo::{conn::TcpListener, Listener}; @@ -52,15 +52,11 @@ impl PingedBot { } } -#[allow(clippy::absolute_paths)] -type Result = std::result::Result>; - lazy_static! { static ref PINGED_BOTS: Mutex> = Mutex::new(Vec::new()); } -#[tokio::main] -async fn main() -> Result<()> { +async fn try_main() -> ServerResult<()> { pretty_env_logger::init(); dotenv::dotenv().ok(); log::info!("Starting the API"); @@ -120,3 +116,12 @@ async fn main() -> Result<()> { } Ok(()) } + +#[tokio::main] +async fn main() -> ExitCode { + if let Err(err) = try_main().await { + eprintln!("{err}"); + return ExitCode::FAILURE; + } + ExitCode::SUCCESS +}