added finer error catching

This commit is contained in:
Nickiel12 2023-08-25 21:57:20 -07:00
parent 8b17e76d42
commit 40131dcad8

View file

@ -16,7 +16,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Opening Config file: {}", args.config_file); println!("Opening Config file: {}", args.config_file);
println!("File exists: {}", std::fs::metadata(args.config_file.clone()).is_ok()); println!("File exists: {}", std::fs::metadata(args.config_file.clone()).is_ok());
let cfg: Config = toml::from_str(std::fs::read_to_string(args.config_file)?.as_str())?; let file_contents = match std::fs::read_to_string(args.config_file) {
Ok(val) => val,
Err(e) => {
println!("Could not read file: {}", e.to_string());
return Ok(());
}
};
let cfg: Config = match toml::from_str(file_contents.as_str()) {
Ok(val) => val,
Err(e) => {
println!("Could not parse file: {}", e.to_string());
return Ok(());
}
};
let mut body_content: String = format!("*Last Updated:* {} \n", chrono::Local::now().format("%D - %H:%M:%S")); let mut body_content: String = format!("*Last Updated:* {} \n", chrono::Local::now().format("%D - %H:%M:%S"));