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.
This commit is contained in:
16
src/main.rs
16
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)
|
||||
|
||||
Reference in New Issue
Block a user