From f956c6125d58f3bd17feeed79369d17e01e1cb20 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 11 Jul 2024 06:38:16 +0200 Subject: [PATCH] Handle both the `Ok` and the `Err` case of `try_join!` --- src/main.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 40b60677..6731feef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use anyhow::{Result}; +use anyhow::Result; use crate::telegram::DispatchWithResult; pub(crate) mod database; @@ -17,11 +17,19 @@ async fn main() -> Result<()> { // Run all services concurrently log::info!("Starting services..."); - tokio::try_join![ + let result = tokio::try_join![ telegram_awaitable, ]; // This should never happen, but just in case... - log::error!("A service has exited, bailing out..."); - anyhow::bail!("A service has exited.") + match result { + Err(error) => { + log::error!("A service has exited with an error, bailing out: {error:?}"); + anyhow::bail!("A service has exited with an error.") + }, + _ => { + log::error!("All service have exited successfully, bailing out..."); + anyhow::bail!("All service have exited successfully.") + } + } }