Skip to content

Commit b2ed5ed

Browse files
author
Danielle Jenkins
committed
Print an error if the config file isn't found
1 parent a76472f commit b2ed5ed

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/main.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,15 +463,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
463463
std::panic::set_hook(Box::new(|panic_info| {
464464
eprintln!("Panic occurred: {}", panic_info);
465465

466-
// Ensure this is always executed after a panic
466+
println!("");
467467
println!("Press Enter to exit...");
468468
io::stdout().flush().unwrap();
469469
let _ = io::stdin().read_line(&mut String::new());
470470
}));
471471

472472
let result = run_main().await;
473473

474-
// Ensure this is always executed
474+
println!("");
475475
println!("Press Enter to exit...");
476476
io::stdout().flush().unwrap();
477477
let _ = io::stdin().read_line(&mut String::new());
@@ -480,7 +480,18 @@ async fn main() -> Result<(), Box<dyn Error>> {
480480
}
481481

482482
async fn run_main() -> Result<(), Box<dyn Error>> {
483-
let config_data = fs::read_to_string("config.toml")?;
483+
484+
let config_path = "config.toml";
485+
let config_data = match fs::read_to_string(config_path) {
486+
Ok(data) => data,
487+
Err(e) => {
488+
eprintln!("Error reading config file: {}", e);
489+
eprintln!("Please ensure that the 'config.toml' file exists in the same directory as the executable.");
490+
eprintln!("You can refer to 'config.toml.example' for an example configuration.");
491+
return Err(Box::new(e));
492+
}
493+
};
494+
484495
let config: Config = toml::from_str(&config_data)?;
485496
let config = Arc::new(config);
486497

0 commit comments

Comments
 (0)