Add filter add/del error to runtime

This commit is contained in:
Félix Saparelli 2021-09-28 22:23:23 +13:00
parent 9bb6e1356a
commit f492bca8c3
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
2 changed files with 18 additions and 2 deletions

View File

@ -9,6 +9,7 @@ use crate::{
action::{Action, PostSpawn, PreSpawn},
command::Shell,
error::RuntimeError,
filter::Filterer,
fs::Watcher,
handler::Handler,
};
@ -81,6 +82,11 @@ impl RuntimeConfig {
self
}
pub fn filterer(&mut self, filterer: Arc<dyn Filterer>) -> &mut Self {
self.action.filterer = filterer;
self
}
/// Set the action handler.
///
/// TODO: notes on how outcome is read immediately after handler returns

View File

@ -1,6 +1,6 @@
//! Error types for critical, runtime, and specialised errors.
use std::path::PathBuf;
use std::{collections::HashMap, path::PathBuf};
use miette::Diagnostic;
use thiserror::Error;
@ -12,6 +12,7 @@ use tokio::{
use crate::{
action,
event::Event,
filter::tagged::{Filter, Matcher},
fs::{self, Watcher},
};
@ -158,7 +159,7 @@ pub enum RuntimeError {
#[diagnostic(code(watchexec::runtime::clearscreen))]
Clearscreen(#[from] clearscreen::Error),
/// Error received when a filter cannot be parsed.
/// Error received when a tagged filter cannot be parsed.
#[error("cannot parse filter `{src}`: {err:?}")]
#[diagnostic(code(watchexec::runtime::filter_parse))]
FilterParse {
@ -166,6 +167,15 @@ pub enum RuntimeError {
err: nom::error::ErrorKind,
// TODO: use miette's source snippet feature
},
/// Error received when a filter cannot be added or removed from a tagged filter list.
#[error("cannot {action} filter: {err:?}")]
#[diagnostic(code(watchexec::runtime::filter_change))]
FilterChange {
action: &'static str,
#[source]
err: watch::error::SendError<HashMap<Matcher, Vec<Filter>>>,
},
}
/// Errors occurring from reconfigs.