diff options
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index f7f4bac..f2fa2ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use std::{ time::Duration, }; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, Context, Result}; use clap::Clap; use evtclib::{Boss, Compression, Log}; use log::{debug, error, info, warn}; @@ -62,12 +62,15 @@ fn main() { let opts = Opts::parse(); if let Err(e) = inner_main(&opts) { error!("{}", e); + e.chain() + .skip(1) + .for_each(|cause| error!("... because: {}", cause)); std::process::exit(1); } } fn inner_main(opts: &Opts) -> Result<()> { - let config = config::load(&opts.config)?; + let config = config::load(&opts.config).context("Could not load configuration")?; match &opts.subcmd { SubCommand::Watch(w) => watch(w, &config)?, SubCommand::Upload(u) => { @@ -75,7 +78,8 @@ fn inner_main(opts: &Opts) -> Result<()> { println!("{}", permalink); if let Some(d) = &config.discord { let log = load_log(&u.path)?; - discord::post_link(&d.auth_token, d.channel_id, log, permalink)?; + discord::post_link(&d.auth_token, d.channel_id, log, permalink) + .context("Could not post link to Discord")?; } } } @@ -88,7 +92,9 @@ fn watch(watch: &Watch, config: &Config) -> Result<()> { let (tx, rx) = channel(); let mut watcher = notify::watcher(tx, Duration::from_secs(WATCH_DELAY_SECONDS))?; - watcher.watch(&watch.dirname, RecursiveMode::Recursive)?; + watcher + .watch(&watch.dirname, RecursiveMode::Recursive) + .context("Could not watch the given directory")?; info!("Watcher set up, watching {:?}", watch.dirname); loop { let event = rx.recv()?; @@ -159,7 +165,8 @@ fn handle_file(config: &Config, filename: &Path) -> Result<()> { info!("Uploaded log, available at {}", permalink); if let Some(d) = &config.discord { - discord::post_link(&d.auth_token, d.channel_id, log, permalink)?; + discord::post_link(&d.auth_token, d.channel_id, log, permalink) + .context("Could not post link to Discord")?; info!("Posted link to Discord"); } |