@@ -10,9 +10,9 @@ use application::Application;
1010
1111use std::path::PathBuf;
1212
13−use anyhow::Error;
13+use anyhow::{Context, Result};
1414
15−fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
15+fn setup_logging(verbosity: u64) -> Result<()> {
1616 let mut base_config = fern::Dispatch::new();
1717
1818 // Let's say we depend on something which whose "info" level messages are too
@@ -27,7 +27,7 @@ fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
2727 _3_or_more => base_config.level(log::LevelFilter::Trace),
2828 };
2929
30− let home = dirs_next::home_dir().expect("can't find the home directory");
30+ let home = dirs_next::home_dir().context("can't find the home directory")?;
3131
3232 // Separate file config so we can include year, month and day in file logs
3333 let file_config = fern::Dispatch::new()
@@ -51,7 +51,7 @@ pub struct Args {
5151 files: Vec<PathBuf>,
5252}
5353
54−fn main() {
54+fn main() -> Result<()> {
5555 let help = format!(
5656 "\
5757{} {}
@@ -89,7 +89,7 @@ FLAGS:
8989 verbosity = 1;
9090 }
9191
92− setup_logging(verbosity).expect("failed to initialize logging.");
92+ setup_logging(verbosity).context("failed to initialize logging")?;
9393
9494 let args = Args {
9595 files: pargs.finish().into_iter().map(|arg| arg.into()).collect(),
@@ -105,17 +105,16 @@ FLAGS:
105105 .as_deref()
106106 .unwrap_or(include_bytes!("../../languages.toml"));
107107
108− LOADER.get_or_init(|| {
109− let config = toml::from_slice(toml).expect("Could not parse languages.toml");
110− Loader::new(config)
111− });
108+ let config = toml::from_slice(toml).context("Could not parse languages.toml")?;
109+ LOADER.get_or_init(|| Loader::new(config));
112110
113− let runtime = tokio::runtime::Runtime::new().unwrap();
111+ let runtime = tokio::runtime::Runtime::new().context("unable to start tokio runtime")?;
114112
115113 // TODO: use the thread local executor to spawn the application task separately from the work pool
114+ let mut app = Application::new(args).context("unable to create new appliction")?;
116115 runtime.block_on(async move {
117− let mut app = Application::new(args).unwrap();
118−
119116 app.run().await;
120117 });
118+
119+ Ok(())
121120}