Move TaggedFiltererError into main error mod

This commit is contained in:
Félix Saparelli 2022-01-16 19:14:31 +13:00
parent b29b3bf1e0
commit 44a44a50d1
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
6 changed files with 101 additions and 88 deletions

View File

@ -1,8 +1,17 @@
use std::collections::HashMap;
use ignore::gitignore::Gitignore;
use miette::Diagnostic;
use thiserror::Error;
use tokio::sync::watch;
use tokio::sync::watch::{self, error::SendError};
use crate::{action, fs};
use crate::{
action,
error::RuntimeError,
filter::tagged::{Filter, Matcher},
fs,
ignore::IgnoreFilterer,
};
/// Errors occurring from reconfigs.
#[derive(Debug, Diagnostic, Error)]
@ -73,3 +82,79 @@ impl SignalParseError {
}
}
}
/// Errors emitted by the TaggedFilterer.
#[derive(Debug, Diagnostic, Error)]
#[non_exhaustive]
#[diagnostic(url(docsrs))]
pub enum TaggedFiltererError {
/// Generic I/O error, with no additional context.
#[error("io(unspecified): {0}")]
#[diagnostic(code(watchexec::filter::io_error_generic))]
IoErrorGeneric(#[from] std::io::Error),
/// Generic I/O error, with some context.
#[error("io({about}): {err}")]
#[diagnostic(code(watchexec::filter::io_error))]
IoError {
/// What it was about.
about: &'static str,
/// The I/O error which occurred.
#[source]
err: std::io::Error,
},
/// Error received when a tagged filter cannot be parsed.
#[error("cannot parse filter `{src}`: {err:?}")]
#[diagnostic(code(watchexec::filter::tagged::parse))]
Parse {
/// The source of the filter.
#[source_code]
src: String,
/// What went wrong.
err: nom::error::ErrorKind,
},
/// Error received when a filter cannot be added or removed from a tagged filter list.
#[error("cannot {action} filter: {err:?}")]
#[diagnostic(code(watchexec::filter::tagged::filter_change))]
FilterChange {
/// The action that was attempted.
action: &'static str,
/// The underlying error.
#[source]
err: SendError<HashMap<Matcher, Vec<Filter>>>,
},
/// Error received when a glob cannot be parsed.
#[error("cannot parse glob: {0}")]
#[diagnostic(code(watchexec::filter::tagged::glob_parse))]
GlobParse(#[source] ignore::Error),
/// Error received when a compiled globset cannot be changed.
#[error("cannot change compiled globset: {0:?}")]
#[diagnostic(code(watchexec::filter::tagged::globset_change))]
GlobsetChange(#[source] SendError<Option<Gitignore>>),
/// Error received about the internal ignore filterer.
#[error("ignore filterer: {0}")]
#[diagnostic(code(watchexec::filter::tagged::ignore))]
Ignore(#[source] RuntimeError),
/// Error received when a new ignore filterer cannot be swapped in.
#[error("cannot swap in new ignore filterer: {0:?}")]
#[diagnostic(code(watchexec::filter::tagged::ignore_swap))]
IgnoreSwap(#[source] SendError<IgnoreFilterer>),
}
impl From<TaggedFiltererError> for RuntimeError {
fn from(err: TaggedFiltererError) -> Self {
Self::Filterer {
kind: "tagged",
err: Box::new(err) as _,
}
}
}

View File

@ -12,8 +12,8 @@ use tracing::{debug, trace, trace_span, warn};
use unicase::UniCase;
use crate::error::RuntimeError;
use crate::error::TaggedFiltererError;
use crate::event::{Event, FileType, ProcessEnd, Tag};
use crate::filter::tagged::error::TaggedFiltererError;
use crate::filter::Filterer;
use crate::ignore::{IgnoreFile, IgnoreFilterer};
use crate::signal::process::SubSignal;
@ -22,7 +22,6 @@ use crate::signal::source::MainSignal;
// to make filters
pub use regex::Regex;
pub mod error;
pub mod files;
mod parse;
pub mod swaplock;

View File

@ -1,78 +0,0 @@
//! Error type for TaggedFilterer.
use std::collections::HashMap;
use ignore::gitignore::Gitignore;
use miette::Diagnostic;
use thiserror::Error;
use tokio::sync::watch::error::SendError;
use crate::{
error::RuntimeError,
filter::tagged::{Filter, Matcher},
ignore::IgnoreFilterer,
};
/// Errors emitted by the TaggedFilterer.
#[derive(Debug, Diagnostic, Error)]
#[non_exhaustive]
#[diagnostic(url(docsrs))]
pub enum TaggedFiltererError {
/// Generic I/O error, with no additional context.
#[error(transparent)]
#[diagnostic(code(watchexec::filter::tagged::io_error))]
IoError(#[from] std::io::Error),
/// Error received when a tagged filter cannot be parsed.
#[error("cannot parse filter `{src}`: {err:?}")]
#[diagnostic(code(watchexec::filter::tagged::parse))]
Parse {
/// The source of the filter.
#[source_code]
src: String,
/// What went wrong.
err: nom::error::ErrorKind,
},
/// Error received when a filter cannot be added or removed from a tagged filter list.
#[error("cannot {action} filter: {err:?}")]
#[diagnostic(code(watchexec::filter::tagged::filter_change))]
FilterChange {
/// The action that was attempted.
action: &'static str,
/// The underlying error.
#[source]
err: SendError<HashMap<Matcher, Vec<Filter>>>,
},
/// Error received when a glob cannot be parsed.
#[error("cannot parse glob: {0}")]
#[diagnostic(code(watchexec::filter::tagged::glob_parse))]
GlobParse(#[source] ignore::Error),
/// Error received when a compiled globset cannot be changed.
#[error("cannot change compiled globset: {0:?}")]
#[diagnostic(code(watchexec::filter::tagged::globset_change))]
GlobsetChange(#[source] SendError<Option<Gitignore>>),
/// Error received about the internal ignore filterer.
#[error("ignore filterer: {0}")]
#[diagnostic(code(watchexec::filter::tagged::ignore))]
Ignore(#[source] RuntimeError),
/// Error received when a new ignore filterer cannot be swapped in.
#[error("cannot swap in new ignore filterer: {0:?}")]
#[diagnostic(code(watchexec::filter::tagged::ignore_swap))]
IgnoreSwap(#[source] SendError<IgnoreFilterer>),
}
impl From<TaggedFiltererError> for RuntimeError {
fn from(err: TaggedFiltererError) -> Self {
Self::Filterer {
kind: "tagged",
err: Box::new(err) as _,
}
}
}

View File

@ -9,9 +9,12 @@ use std::{
use tokio::fs::read_to_string;
use crate::ignore::{discover_file, IgnoreFile};
use crate::{
error::TaggedFiltererError,
ignore::{discover_file, IgnoreFile},
};
use super::{error::TaggedFiltererError, Filter};
use super::Filter;
/// A filter file.
///

View File

@ -11,10 +11,12 @@ use nom::{
use regex::Regex;
use tracing::trace;
use crate::error::TaggedFiltererError;
use super::*;
impl FromStr for Filter {
type Err = error::TaggedFiltererError;
type Err = TaggedFiltererError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
fn matcher(i: &str) -> IResult<&str, Matcher> {
@ -129,7 +131,7 @@ impl FromStr for Filter {
trace!(src=?s, filter=?f, "parsed tagged filter");
f
})
.map_err(|e| error::TaggedFiltererError::Parse {
.map_err(|e| TaggedFiltererError::Parse {
src: s.to_string(),
err: e.code,
})

View File

@ -1,7 +1,9 @@
use std::{collections::HashSet, str::FromStr};
use regex::Regex;
use watchexec::filter::tagged::{error::TaggedFiltererError, Filter, Matcher, Op, Pattern};
use watchexec::{
error::TaggedFiltererError,
filter::tagged::{Filter, Matcher, Op, Pattern, Regex},
};
mod helpers;
use helpers::tagged::*;