From 83d6c3567392e70160a8404b2b9c71e0e64983e6 Mon Sep 17 00:00:00 2001 From: Tony C Sidrock Date: Sat, 10 Jan 2026 21:34:17 +0000 Subject: [PATCH] next: Enhance error handling in main function by improving thread join error reporting and adding logging for reader thread errors. --- src/main.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index c03d481..30c37bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,24 +3,38 @@ use squitterator::{ }; use clap::Parser; +use log::error; use std::sync::Arc; fn main() -> AppResult<()> { let args = Arc::new(Args::parse()); + // Initialize error logging if specified if let Some(error_log_file) = &args.error_log { initialize_logger(error_log_file)?; - }; + } + // Set observer coordinates if provided if let Some(coord_str) = &args.observer_coord { - set_observer_coords_from_str(coord_str) - }; + set_observer_coords_from_str(coord_str); + } let planes = Planes::new(); - let reader_thread = spawn_reader_thread(args, planes); + + // Wait for the reader thread to complete reader_thread .join() - .expect("Couldn't join on the associated thread")?; + .map_err(|_| { + std::io::Error::new( + std::io::ErrorKind::Other, + "Failed to join reader thread: thread panicked", + ) + })? + .map_err(|e| { + error!("Reader thread error: {}", e); + e + })?; + Ok(()) }