aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2020-06-18 01:56:20 +0200
committerDaniel Schadt <kingdread@gmx.de>2020-06-18 01:56:42 +0200
commit507757d227aa00874a2d33caed1a78c5b8cc7132 (patch)
treeba3ae66bbb43ce1f4499f32a26f6ffcb372bb8d4 /src
parentd0f4c5c0af0b60bccbe1618c0fab0fec0f0d4140 (diff)
downloadezau-507757d227aa00874a2d33caed1a78c5b8cc7132.tar.gz
ezau-507757d227aa00874a2d33caed1a78c5b8cc7132.tar.bz2
ezau-507757d227aa00874a2d33caed1a78c5b8cc7132.zip
add some more context to some errors
Some error messages currently look very weird. For example, if the given configuration file does not exist, it gives you an error about a missing file - which could also be the file to upload though, as the error doesn't specify. Therefore, some more context for the error messages is nice. The "sourceback" could still use some work.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs17
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");
}