From 7d5c88f064a6ae4684a42f85b2459092ab791566 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 13 Sep 2021 10:44:43 -0700 Subject: [PATCH] subscriber: fix `filter::ParseError` accidentally being renamed (#1558) I accidentally renamed this type in PR #1550 after getting confused by a renaming import that I thought was publicly re-exported, but it wasn't actually..sorry about that! This commit renames (or...un-renames?) the type. Whoopsie! Fixes #1557 --- tracing-subscriber/src/filter/directive.rs | 30 +++++++++---------- .../src/filter/env/directive.rs | 8 ++--- tracing-subscriber/src/filter/env/mod.rs | 12 ++++---- tracing-subscriber/src/filter/mod.rs | 2 +- tracing-subscriber/src/filter/targets.rs | 4 +-- 5 files changed, 27 insertions(+), 29 deletions(-) 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 2f3eea4c96..1cd3285696 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 84c22e7906..f15ed13e23 100644 --- a/tracing-subscriber/src/filter/env/mod.rs +++ b/tracing-subscriber/src/filter/env/mod.rs @@ -13,7 +13,7 @@ use crate::{ subscribe::{Context, Subscribe}, sync::RwLock, }; -use directive::DirectiveParseError; +use directive::ParseError; use std::{cell::RefCell, collections::HashMap, env, error::Error, fmt, str::FromStr}; use tracing_core::{ callsite, @@ -133,7 +133,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(',') @@ -488,7 +488,7 @@ impl Subscribe for EnvFilter { } impl FromStr for EnvFilter { - type Err = directive::DirectiveParseError; + type Err = directive::ParseError; fn from_str(spec: &str) -> Result { Self::try_new(spec) @@ -539,8 +539,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 f4c8a5db1f..b48817323f 100644 --- a/tracing-subscriber/src/filter/mod.rs +++ b/tracing-subscriber/src/filter/mod.rs @@ -17,7 +17,7 @@ mod level; mod subscriber_filters; 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_psf_stubs::*; diff --git a/tracing-subscriber/src/filter/targets.rs b/tracing-subscriber/src/filter/targets.rs index 1850e25c8b..1bd16e8ee3 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, }, subscribe, @@ -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)