Add docs for error_handler as it's a bit tricky
This commit is contained in:
parent
816313303a
commit
019018c93e
|
@ -47,7 +47,17 @@ pub struct InitConfig {
|
||||||
/// If the handler errors, [_that_ error][crate::error::RuntimeError::Handler] is immediately
|
/// If the handler errors, [_that_ error][crate::error::RuntimeError::Handler] is immediately
|
||||||
/// given to the handler. If that second handler call errors as well, its error is ignored.
|
/// given to the handler. If that second handler call errors as well, its error is ignored.
|
||||||
///
|
///
|
||||||
/// Only used at construction time, cannot be changed via reconfiguration.
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use std::convert::Infallible;
|
||||||
|
/// # use watchexec::config::InitConfigBuilder;
|
||||||
|
/// InitConfigBuilder::default()
|
||||||
|
/// .error_handler(Box::new(|err| async move {
|
||||||
|
/// tracing::error!("{}", err);
|
||||||
|
/// Ok::<(), Infallible>(())
|
||||||
|
/// }));
|
||||||
|
/// ```
|
||||||
#[builder(default = "Box::new(()) as _")]
|
#[builder(default = "Box::new(()) as _")]
|
||||||
pub error_handler: Box<dyn Handler<RuntimeError> + Send>,
|
pub error_handler: Box<dyn Handler<RuntimeError> + Send>,
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,7 @@ where
|
||||||
|
|
||||||
impl<T> Handler<T> for () {
|
impl<T> Handler<T> for () {
|
||||||
fn handle(&mut self, _data: T) -> Result<(), Box<dyn Error>> {
|
fn handle(&mut self, _data: T) -> Result<(), Box<dyn Error>> {
|
||||||
Ok(()).map_err(|e: std::convert::Infallible| Box::new(e) as _)
|
Ok::<(), std::convert::Infallible>(()).map_err(|e| Box::new(e) as _)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
//!
|
//!
|
||||||
//! #[tokio::main]
|
//! #[tokio::main]
|
||||||
//! async fn main() {
|
//! async fn main() {
|
||||||
//! let init = InitConfigBuilder::new()
|
//! let init = InitConfigBuilder::default()
|
||||||
//! .error_handler(PrintDebug(std::io::stderr()));
|
//! .error_handler(PrintDebug(std::io::stderr()));
|
||||||
//!
|
//!
|
||||||
//! let mut runtime = RuntimeConfigBuilder::new()
|
//! let mut runtime = RuntimeConfigBuilder::default()
|
||||||
//! config.pathset(["watchexec.conf"]);
|
//! config.pathset(["watchexec.conf"]);
|
||||||
//!
|
//!
|
||||||
//! let conf = YourConfigFormat::load_from_file("watchexec.conf").await?;
|
//! let conf = YourConfigFormat::load_from_file("watchexec.conf").await?;
|
||||||
|
@ -62,11 +62,11 @@ pub mod command;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
pub mod handler;
|
|
||||||
pub mod signal;
|
pub mod signal;
|
||||||
|
|
||||||
// the core experience
|
// the core experience
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
pub mod handler;
|
||||||
mod watchexec;
|
mod watchexec;
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl Watchexec {
|
||||||
|
|
||||||
let error_hook = subtask!(error_hook(er_r, eh));
|
let error_hook = subtask!(error_hook(er_r, eh));
|
||||||
|
|
||||||
try_join!(action, fs, signal).map(drop)
|
try_join!(action, error_hook, fs, signal).map(drop)
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(Arc::new(Self {
|
Ok(Arc::new(Self {
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use tokio::time::sleep;
|
||||||
|
use watchexec::{
|
||||||
|
config::{InitConfigBuilder, RuntimeConfigBuilder},
|
||||||
|
Watchexec,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> color_eyre::eyre::Result<()> {
|
||||||
|
tracing_subscriber::fmt::init();
|
||||||
|
color_eyre::install()?;
|
||||||
|
|
||||||
|
let init = InitConfigBuilder::default()
|
||||||
|
.error_handler(Box::new(|err| async move {
|
||||||
|
eprintln!("Watchexec Runtime Error: {}", err);
|
||||||
|
Ok::<(), std::convert::Infallible>(())
|
||||||
|
}))
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
let runtime = RuntimeConfigBuilder::default().build()?;
|
||||||
|
|
||||||
|
let wx = Watchexec::new(init, runtime)?;
|
||||||
|
wx.main();
|
||||||
|
|
||||||
|
// TODO: induce an error here
|
||||||
|
|
||||||
|
sleep(Duration::from_secs(1)).await;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue