diff --git a/tracing-subscriber/src/filter/directive.rs b/tracing-subscriber/src/filter/directive.rs index 545018e8b7..61cc00a9ec 100644 --- a/tracing-subscriber/src/filter/directive.rs +++ b/tracing-subscriber/src/filter/directive.rs @@ -3,7 +3,7 @@ use std::{cmp::Ordering, error::Error, fmt, iter::FromIterator, str::FromStr}; use tracing_core::Metadata; /// Indicates that a string could not be parsed as a filtering directive. #[derive(Debug)] -pub struct DirectiveParseError { +pub struct ParseError { kind: ParseErrorKind, } @@ -260,7 +260,7 @@ impl fmt::Display for StaticDirective { } impl FromStr for StaticDirective { - type Err = DirectiveParseError; + type Err = ParseError; fn from_str(s: &str) -> Result { // This method parses a filtering directive in one of the following @@ -273,7 +273,7 @@ impl FromStr for StaticDirective { let mut split = s.split('='); let part0 = split .next() - .ok_or_else(|| DirectiveParseError::msg("string must not be empty"))?; + .ok_or_else(|| ParseError::msg("string must not be empty"))?; // Directive includes an `=`: // * `foo=trace` @@ -281,7 +281,7 @@ impl FromStr for StaticDirective { // * `foo[{bar,baz}]=trace` if let Some(part1) = split.next() { if split.next().is_some() { - return Err(DirectiveParseError::msg( + return Err(ParseError::msg( "too many '=' in filter directive, expected 0 or 1", )); } @@ -294,14 +294,14 @@ impl FromStr for StaticDirective { // * `foo[{bar,baz}]=trace` if let Some(maybe_fields) = split.next() { if split.next().is_some() { - return Err(DirectiveParseError::msg( + return Err(ParseError::msg( "too many '[{' in filter directive, expected 0 or 1", )); } - let fields = maybe_fields.strip_suffix("}]").ok_or_else(|| { - DirectiveParseError::msg("expected fields list to end with '}]'") - })?; + let fields = maybe_fields + .strip_suffix("}]") + .ok_or_else(|| ParseError::msg("expected fields list to end with '}]'"))?; field_names.extend(fields.split(',').filter_map(|s| { if s.is_empty() { None @@ -339,21 +339,21 @@ impl FromStr for StaticDirective { // === impl ParseError === -impl DirectiveParseError { +impl ParseError { pub(crate) fn new() -> Self { - DirectiveParseError { + ParseError { kind: ParseErrorKind::Other(None), } } pub(crate) fn msg(s: &'static str) -> Self { - DirectiveParseError { + ParseError { kind: ParseErrorKind::Other(Some(s)), } } } -impl fmt::Display for DirectiveParseError { +impl fmt::Display for ParseError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.kind { ParseErrorKind::Other(None) => f.pad("invalid filter directive"), @@ -364,7 +364,7 @@ impl fmt::Display for DirectiveParseError { } } -impl Error for DirectiveParseError { +impl Error for ParseError { fn description(&self) -> &str { "invalid filter directive" } @@ -378,7 +378,7 @@ impl Error for DirectiveParseError { } } -impl From> for DirectiveParseError { +impl From> for ParseError { fn from(e: Box) -> Self { Self { kind: ParseErrorKind::Field(e), @@ -386,7 +386,7 @@ impl From> for DirectiveParseError { } } -impl From for DirectiveParseError { +impl From for ParseError { fn from(l: level::ParseError) -> Self { Self { kind: ParseErrorKind::Level(l), diff --git a/tracing-subscriber/src/filter/env/directive.rs b/tracing-subscriber/src/filter/env/directive.rs index 207beaea36..538df16111 100644 --- a/tracing-subscriber/src/filter/env/directive.rs +++ b/tracing-subscriber/src/filter/env/directive.rs @@ -1,5 +1,5 @@ use super::FilterVec; -pub(crate) use crate::filter::directive::{DirectiveParseError, StaticDirective}; +pub(crate) use crate::filter::directive::{ParseError, StaticDirective}; use crate::filter::{ directive::{DirectiveSet, Match}, env::{field, FieldMap}, @@ -145,7 +145,7 @@ impl Match for Directive { } impl FromStr for Directive { - type Err = DirectiveParseError; + type Err = ParseError; fn from_str(from: &str) -> Result { lazy_static! { static ref DIRECTIVE_RE: Regex = Regex::new( @@ -183,9 +183,7 @@ impl FromStr for Directive { "#).unwrap(); } - let caps = DIRECTIVE_RE - .captures(from) - .ok_or_else(DirectiveParseError::new)?; + let caps = DIRECTIVE_RE.captures(from).ok_or_else(ParseError::new)?; if let Some(level) = caps .name("global_level") diff --git a/tracing-subscriber/src/filter/env/mod.rs b/tracing-subscriber/src/filter/env/mod.rs index 7fc18d856f..d9a9b55f35 100644 --- a/tracing-subscriber/src/filter/env/mod.rs +++ b/tracing-subscriber/src/filter/env/mod.rs @@ -13,7 +13,7 @@ use crate::{ layer::{Context, Layer}, sync::RwLock, }; -use directive::DirectiveParseError; +use directive::ParseError; use std::{cell::RefCell, collections::HashMap, env, error::Error, fmt, str::FromStr}; use tracing_core::{ callsite, @@ -131,7 +131,7 @@ pub struct FromEnvError { #[derive(Debug)] enum ErrorKind { - Parse(DirectiveParseError), + Parse(ParseError), Env(env::VarError), } @@ -170,7 +170,7 @@ impl EnvFilter { /// Returns a new `EnvFilter` from the directives in the given string, /// or an error if any are invalid. - pub fn try_new>(dirs: S) -> Result { + pub fn try_new>(dirs: S) -> Result { let directives = dirs .as_ref() .split(',') @@ -489,7 +489,7 @@ impl Layer for EnvFilter { } impl FromStr for EnvFilter { - type Err = directive::DirectiveParseError; + type Err = directive::ParseError; fn from_str(spec: &str) -> Result { Self::try_new(spec) @@ -540,8 +540,8 @@ impl fmt::Display for EnvFilter { // ===== impl FromEnvError ===== -impl From for FromEnvError { - fn from(p: directive::DirectiveParseError) -> Self { +impl From for FromEnvError { + fn from(p: directive::ParseError) -> Self { Self { kind: ErrorKind::Parse(p), } diff --git a/tracing-subscriber/src/filter/mod.rs b/tracing-subscriber/src/filter/mod.rs index edd38a51f1..37575bb020 100644 --- a/tracing-subscriber/src/filter/mod.rs +++ b/tracing-subscriber/src/filter/mod.rs @@ -17,7 +17,7 @@ mod layer_filters; mod level; mod targets; -pub use self::directive::DirectiveParseError; +pub use self::directive::ParseError; pub use self::filter_fn::*; #[cfg(not(feature = "registry"))] pub(crate) use self::has_plf_stubs::*; diff --git a/tracing-subscriber/src/filter/targets.rs b/tracing-subscriber/src/filter/targets.rs index 7b5c99c9a0..70634e3b92 100644 --- a/tracing-subscriber/src/filter/targets.rs +++ b/tracing-subscriber/src/filter/targets.rs @@ -1,6 +1,6 @@ use crate::{ filter::{ - directive::{DirectiveParseError, DirectiveSet, StaticDirective}, + directive::{DirectiveSet, ParseError, StaticDirective}, LevelFilter, }, layer, @@ -302,7 +302,7 @@ where } impl FromStr for Targets { - type Err = DirectiveParseError; + type Err = ParseError; fn from_str(s: &str) -> Result { s.split(',') .map(StaticDirective::from_str)