Skip to content

Commit

Permalink
subscriber: fix filter::ParseError accidentally being renamed (#1558)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hawkw committed Mar 24, 2022
1 parent df4c8bf commit 18fe264
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
30 changes: 15 additions & 15 deletions tracing-subscriber/src/filter/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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<Self, Self::Err> {
// This method parses a filtering directive in one of the following
Expand All @@ -273,15 +273,15 @@ 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`
// * `foo[{bar}]=trace`
// * `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",
));
}
Expand All @@ -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
Expand Down Expand Up @@ -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"),
Expand All @@ -364,7 +364,7 @@ impl fmt::Display for DirectiveParseError {
}
}

impl Error for DirectiveParseError {
impl Error for ParseError {
fn description(&self) -> &str {
"invalid filter directive"
}
Expand All @@ -378,15 +378,15 @@ impl Error for DirectiveParseError {
}
}

impl From<Box<dyn Error + Send + Sync>> for DirectiveParseError {
impl From<Box<dyn Error + Send + Sync>> for ParseError {
fn from(e: Box<dyn Error + Send + Sync>) -> Self {
Self {
kind: ParseErrorKind::Field(e),
}
}
}

impl From<level::ParseError> for DirectiveParseError {
impl From<level::ParseError> for ParseError {
fn from(l: level::ParseError) -> Self {
Self {
kind: ParseErrorKind::Level(l),
Expand Down
8 changes: 3 additions & 5 deletions tracing-subscriber/src/filter/env/directive.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Match for Directive {
}

impl FromStr for Directive {
type Err = DirectiveParseError;
type Err = ParseError;
fn from_str(from: &str) -> Result<Self, Self::Err> {
lazy_static! {
static ref DIRECTIVE_RE: Regex = Regex::new(
Expand Down Expand Up @@ -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")
Expand Down
12 changes: 6 additions & 6 deletions tracing-subscriber/src/filter/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -133,7 +133,7 @@ pub struct FromEnvError {

#[derive(Debug)]
enum ErrorKind {
Parse(DirectiveParseError),
Parse(ParseError),
Env(env::VarError),
}

Expand Down Expand Up @@ -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<S: AsRef<str>>(dirs: S) -> Result<Self, directive::DirectiveParseError> {
pub fn try_new<S: AsRef<str>>(dirs: S) -> Result<Self, directive::ParseError> {
let directives = dirs
.as_ref()
.split(',')
Expand Down Expand Up @@ -488,7 +488,7 @@ impl<C: Collect> Subscribe<C> for EnvFilter {
}

impl FromStr for EnvFilter {
type Err = directive::DirectiveParseError;
type Err = directive::ParseError;

fn from_str(spec: &str) -> Result<Self, Self::Err> {
Self::try_new(spec)
Expand Down Expand Up @@ -539,8 +539,8 @@ impl fmt::Display for EnvFilter {

// ===== impl FromEnvError =====

impl From<directive::DirectiveParseError> for FromEnvError {
fn from(p: directive::DirectiveParseError) -> Self {
impl From<directive::ParseError> for FromEnvError {
fn from(p: directive::ParseError) -> Self {
Self {
kind: ErrorKind::Parse(p),
}
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
4 changes: 2 additions & 2 deletions tracing-subscriber/src/filter/targets.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
filter::{
directive::{DirectiveParseError, DirectiveSet, StaticDirective},
directive::{DirectiveSet, ParseError, StaticDirective},
LevelFilter,
},
subscribe,
Expand Down Expand Up @@ -302,7 +302,7 @@ where
}

impl FromStr for Targets {
type Err = DirectiveParseError;
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
s.split(',')
.map(StaticDirective::from_str)
Expand Down

0 comments on commit 18fe264

Please sign in to comment.