From 4b691291db28872a40347af943b102d77f18f208 Mon Sep 17 00:00:00 2001 From: adenoz Date: Wed, 18 Jan 2023 14:23:48 +1100 Subject: [PATCH] improved main.rs error handling --- src/main.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index b69011b..229ab10 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,12 @@ mod observations; use std::env::var; +use std::error::Error; #[tokio::main] -async fn main() { - observations::get_observations() - .await - .expect("The get observations function didn't seem to work"); +async fn main() -> Result<(), Box> { + observations::get_observations().await?; + Ok(()) } // This function has been left in main.rs as this will also be used by a future forecasts.rs module @@ -18,16 +18,12 @@ fn get_config_path() -> String { // We need to clean the start and end of this string println!("short path {:?}", home_dir); // We need to convert the type to String - let hd_string = format!( - "{:?}",home_dir - ); + let hd_string = format!("{:?}", home_dir); let start = 5; // This is to remove formatting from start of file path - let length = hd_string.len(); - let end = length-2; // This is to remove same from end + let length = hd_string.len(); + let end = length - 2; // This is to remove same from end let clean_dir = &hd_string[start..end]; // Now that we have a clean string we can amend the rest - let config_path = format!( - "/{}/.config/rusqttbom/config.toml", clean_dir - ); + let config_path = format!("/{}/.config/rusqttbom/config.toml", clean_dir); config_path -} \ No newline at end of file +}