mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-28 14:11:34 +02:00
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
|
||||
/// 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 _")]
|
||||
pub error_handler: Box<dyn Handler<RuntimeError> + Send>,
|
||||
|
||||
|
@ -162,7 +162,7 @@ where
|
||||
|
||||
impl<T> Handler<T> for () {
|
||||
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]
|
||||
//! async fn main() {
|
||||
//! let init = InitConfigBuilder::new()
|
||||
//! let init = InitConfigBuilder::default()
|
||||
//! .error_handler(PrintDebug(std::io::stderr()));
|
||||
//!
|
||||
//! let mut runtime = RuntimeConfigBuilder::new()
|
||||
//! let mut runtime = RuntimeConfigBuilder::default()
|
||||
//! config.pathset(["watchexec.conf"]);
|
||||
//!
|
||||
//! let conf = YourConfigFormat::load_from_file("watchexec.conf").await?;
|
||||
@ -62,11 +62,11 @@ pub mod command;
|
||||
pub mod error;
|
||||
pub mod event;
|
||||
pub mod fs;
|
||||
pub mod handler;
|
||||
pub mod signal;
|
||||
|
||||
// the core experience
|
||||
pub mod config;
|
||||
pub mod handler;
|
||||
mod watchexec;
|
||||
|
||||
#[doc(inline)]
|
||||
|
@ -70,7 +70,7 @@ impl Watchexec {
|
||||
|
||||
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 {
|
||||
|
31
lib/tests/error_handler.rs
Normal file
31
lib/tests/error_handler.rs
Normal file
@ -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
Block a user