Add RuntimeError::from_handler utility

This commit is contained in:
Félix Saparelli 2021-08-19 20:30:35 +12:00
parent 4e4a8e6853
commit 6f3abdeaea
No known key found for this signature in database
GPG key ID: B948C4BAE44FC474

View file

@ -102,6 +102,22 @@ pub enum RuntimeError {
#[source]
err: mpsc::error::TrySendError<Event>,
},
/// Error received when a [`Handler`][crate::Handler] errors.
///
/// The error is completely opaque, having been flattened into a string at the error point.
#[error("handler error while {ctx}: {err}")]
#[diagnostic(code(watchexec::runtime::handler))]
Handler { ctx: &'static str, err: String },
}
impl RuntimeError {
pub(crate) fn from_handler(ctx: &'static str, err: impl std::error::Error) -> Self {
Self::Handler {
ctx,
err: err.to_string(),
}
}
}
/// Errors occurring from reconfigs.