From a1308507afa7f7dcfb8fc013aca748cccb71dea0 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 5 Apr 2025 06:55:57 -0500 Subject: [PATCH] main: Add better config/init error messages The default messages printed when the process panics because the configuration could not be loaded or the application context could not be initialized are somewhat difficult to read. Instead of calling `unwrap` in these cases, we need to explicitly handle the errors and print more appropriate messages. --- src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index c729ca1..24fcd5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,8 +78,20 @@ async fn rocket() -> _ { let rocket = rocket::build(); - let config: Config = rocket.figment().extract().unwrap(); - let ctx = Context::init(config).unwrap(); + let config: Config = match rocket.figment().extract() { + Ok(c) => c, + Err(e) => { + error!("Could not load configuration: {}", e); + std::process::exit(1); + }, + }; + let ctx = match Context::init(config) { + Ok(c) => c, + Err(e) => { + error!("Could not initialize application context: {}", e); + std::process::exit(1); + }, + }; rocket .manage(ctx)