2021-12-31 13:33:52 +01:00
|
|
|
use std::convert::Infallible;
|
2021-12-23 15:37:51 +01:00
|
|
|
|
|
|
|
use clap::ArgMatches;
|
2023-01-06 14:53:49 +01:00
|
|
|
use miette::Report;
|
2022-01-26 22:48:24 +01:00
|
|
|
use tracing::error;
|
2022-02-12 07:59:02 +01:00
|
|
|
use watchexec::{
|
|
|
|
config::InitConfig,
|
|
|
|
error::{FsWatcherError, RuntimeError},
|
|
|
|
handler::SyncFnHandler,
|
|
|
|
ErrorHook,
|
|
|
|
};
|
2021-12-23 15:37:51 +01:00
|
|
|
|
2023-01-06 14:53:49 +01:00
|
|
|
pub fn init(_args: &ArgMatches) -> InitConfig {
|
2021-12-23 15:37:51 +01:00
|
|
|
let mut config = InitConfig::default();
|
2022-01-10 08:47:06 +01:00
|
|
|
config.on_error(SyncFnHandler::from(
|
2022-01-30 15:16:48 +01:00
|
|
|
|err: ErrorHook| -> std::result::Result<(), Infallible> {
|
2022-01-26 22:48:24 +01:00
|
|
|
if let RuntimeError::IoError {
|
|
|
|
about: "waiting on process group",
|
|
|
|
..
|
2022-01-30 15:16:48 +01:00
|
|
|
} = err.error
|
2022-01-26 22:48:24 +01:00
|
|
|
{
|
|
|
|
// "No child processes" and such
|
|
|
|
// these are often spurious, so condemn them to -v only
|
2022-01-30 15:16:48 +01:00
|
|
|
error!("{}", err.error);
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
2022-02-12 07:59:02 +01:00
|
|
|
if let RuntimeError::FsWatcher {
|
|
|
|
err:
|
|
|
|
FsWatcherError::Create { .. }
|
|
|
|
| FsWatcherError::TooManyWatches { .. }
|
|
|
|
| FsWatcherError::TooManyHandles { .. },
|
|
|
|
..
|
|
|
|
} = err.error
|
|
|
|
{
|
2022-01-30 15:16:48 +01:00
|
|
|
err.elevate();
|
2022-01-26 22:48:24 +01:00
|
|
|
return Ok(());
|
|
|
|
}
|
2021-12-31 13:33:52 +01:00
|
|
|
|
2022-01-10 08:47:06 +01:00
|
|
|
if cfg!(debug_assertions) {
|
2022-01-30 15:16:48 +01:00
|
|
|
eprintln!("[[{:?}]]", err.error);
|
2022-01-10 08:47:06 +01:00
|
|
|
}
|
2021-12-31 13:33:52 +01:00
|
|
|
|
2022-01-30 15:16:48 +01:00
|
|
|
eprintln!("[[Error (not fatal)]]\n{}", Report::new(err.error));
|
2022-01-30 15:01:00 +01:00
|
|
|
|
2022-01-10 08:47:06 +01:00
|
|
|
Ok(())
|
|
|
|
},
|
|
|
|
));
|
2021-12-31 13:33:52 +01:00
|
|
|
|
2023-01-06 14:53:49 +01:00
|
|
|
config
|
2021-12-23 15:37:51 +01:00
|
|
|
}
|