Skip to content

Commit

Permalink
improved main.rs error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
adenoz committed Jan 18, 2023
1 parent 02deb3e commit 4b69129
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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<dyn Error>> {
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
Expand All @@ -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
}
}

0 comments on commit 4b69129

Please sign in to comment.