Adjust display of errors and exit notify

This commit is contained in:
Félix Saparelli 2022-01-01 01:33:52 +13:00
parent 7fa657fc48
commit 163bcc3022
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
2 changed files with 22 additions and 6 deletions

View File

@ -1,11 +1,27 @@
use std::io::stderr;
use std::convert::Infallible;
use clap::ArgMatches;
use miette::Result;
use watchexec::{config::InitConfig, handler::PrintDisplay};
use tracing::error;
use watchexec::{config::InitConfig, handler::SyncFnHandler, error::RuntimeError};
pub fn init(_args: &ArgMatches<'static>) -> Result<InitConfig> {
let mut config = InitConfig::default();
config.on_error(PrintDisplay(stderr()));
config.on_error(SyncFnHandler::from(|data| -> std::result::Result<(), Infallible> {
if let RuntimeError::IoError(_) = data {
// these are often spurious, so condemn them to -v only
error!("{}", data);
return Ok(());
}
if cfg!(debug_assertions) {
eprintln!("[[{:?}]]", data);
} else {
eprintln!("[[{}]]", data);
}
Ok(())
}));
Ok(config)
}

View File

@ -154,7 +154,7 @@ pub fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
};
if printit {
eprintln!("{}", msg);
eprintln!("[[{}]]", msg);
}
if notif {
@ -164,7 +164,7 @@ pub fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
.show()
.map(drop)
.unwrap_or_else(|err| {
eprintln!("Failed to send desktop notification: {}", err);
eprintln!("[[Failed to send desktop notification: {}]]", err);
});
}
@ -218,7 +218,7 @@ pub fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
.show()
.map(drop)
.unwrap_or_else(|err| {
eprintln!("Failed to send desktop notification: {}", err);
eprintln!("[[Failed to send desktop notification: {}]]", err);
});
}