mirror of https://github.com/passcod/cargo-watch
Handle runtime errors properly
This commit is contained in:
parent
1c1fb4d8ad
commit
537182c16e
|
@ -1,15 +1,44 @@
|
|||
use std::convert::Infallible;
|
||||
|
||||
use miette::Result;
|
||||
use watchexec::{config::InitConfig, handler::SyncFnHandler};
|
||||
use miette::{Report, Result};
|
||||
use tracing::error;
|
||||
use watchexec::{
|
||||
config::InitConfig,
|
||||
error::{FsWatcherError, RuntimeError},
|
||||
handler::SyncFnHandler,
|
||||
ErrorHook,
|
||||
};
|
||||
|
||||
use crate::args::Args;
|
||||
|
||||
pub fn init(_args: &Args) -> Result<InitConfig> {
|
||||
let mut config = InitConfig::default();
|
||||
config.on_error(SyncFnHandler::from(
|
||||
|data| -> std::result::Result<(), Infallible> {
|
||||
eprintln!("[[{:?}]]", data);
|
||||
|err: ErrorHook| -> std::result::Result<(), Infallible> {
|
||||
if let RuntimeError::IoError {
|
||||
about: "waiting on process group",
|
||||
..
|
||||
} = err.error
|
||||
{
|
||||
// "No child processes" and such
|
||||
// these are often spurious, so condemn them to --debug only
|
||||
error!("{}", err.error);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let RuntimeError::FsWatcher {
|
||||
err:
|
||||
FsWatcherError::Create { .. }
|
||||
| FsWatcherError::TooManyWatches { .. }
|
||||
| FsWatcherError::TooManyHandles { .. },
|
||||
..
|
||||
} = err.error
|
||||
{
|
||||
err.elevate();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
eprintln!("[[Error (not fatal)]]\n{}", Report::new(err.error));
|
||||
Ok(())
|
||||
},
|
||||
));
|
||||
|
|
|
@ -226,7 +226,7 @@ pub fn runtime(args: &Args, command_order: Vec<&'static str>) -> Result<RuntimeC
|
|||
|
||||
if let Some(runs) = quit_after_n.clone() {
|
||||
if runs.load(Ordering::SeqCst) == 0 {
|
||||
debug!("quitting after n triggers");
|
||||
eprintln!("[[--quit after n--]]");
|
||||
action.outcome(Outcome::Exit);
|
||||
return fut;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue