Use eyre
This commit is contained in:
12
src/main.rs
12
src/main.rs
@ -3,10 +3,10 @@ mod routes;
|
||||
|
||||
use clap::Parser;
|
||||
use dotenv::dotenv;
|
||||
use eyre::Context;
|
||||
use health::HealthState;
|
||||
use rocket::fs::FileServer;
|
||||
use rocket_dyn_templates::Template;
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
@ -20,14 +20,16 @@ struct Opt {
|
||||
}
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
async fn main() -> eyre::Result<()> {
|
||||
dotenv().ok();
|
||||
let opt = Opt::parse();
|
||||
color_eyre::install()?;
|
||||
|
||||
let config = fs::read_to_string(&opt.config)
|
||||
.await
|
||||
.expect("failed to read config file");
|
||||
let config = ron::from_str(&config).expect("failed to parse config file");
|
||||
.wrap_err_with(|| format!("failed to read config file: {:?}", opt.config))?;
|
||||
let config = ron::from_str(&config)
|
||||
.wrap_err_with(|| format!("failed to parse config file: {:?}", opt.config))?;
|
||||
let state = Arc::new(HealthState::new(config));
|
||||
|
||||
let rocket = rocket::build()
|
||||
@ -38,7 +40,7 @@ async fn main() -> io::Result<()> {
|
||||
|
||||
start_poller(state);
|
||||
|
||||
rocket.launch().await.expect("rocket failed to launch");
|
||||
rocket.launch().await.wrap_err("rocket failed to launch")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user