Adjust display of errors and exit notify
This commit is contained in:
parent
7fa657fc48
commit
163bcc3022
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue