Skip to content

Commit 10b0c91

Browse files
committed
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
1 parent 95cdfc5 commit 10b0c91

File tree

5 files changed

+27
-29
lines changed

5 files changed

+27
-29
lines changed

tracing-subscriber/src/filter/directive.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{cmp::Ordering, error::Error, fmt, iter::FromIterator, str::FromStr};
33
use tracing_core::Metadata;
44
/// Indicates that a string could not be parsed as a filtering directive.
55
#[derive(Debug)]
6-
pub struct DirectiveParseError {
6+
pub struct ParseError {
77
kind: ParseErrorKind,
88
}
99

@@ -260,7 +260,7 @@ impl fmt::Display for StaticDirective {
260260
}
261261

262262
impl FromStr for StaticDirective {
263-
type Err = DirectiveParseError;
263+
type Err = ParseError;
264264

265265
fn from_str(s: &str) -> Result<Self, Self::Err> {
266266
// This method parses a filtering directive in one of the following
@@ -273,15 +273,15 @@ impl FromStr for StaticDirective {
273273
let mut split = s.split('=');
274274
let part0 = split
275275
.next()
276-
.ok_or_else(|| DirectiveParseError::msg("string must not be empty"))?;
276+
.ok_or_else(|| ParseError::msg("string must not be empty"))?;
277277

278278
// Directive includes an `=`:
279279
// * `foo=trace`
280280
// * `foo[{bar}]=trace`
281281
// * `foo[{bar,baz}]=trace`
282282
if let Some(part1) = split.next() {
283283
if split.next().is_some() {
284-
return Err(DirectiveParseError::msg(
284+
return Err(ParseError::msg(
285285
"too many '=' in filter directive, expected 0 or 1",
286286
));
287287
}
@@ -294,14 +294,14 @@ impl FromStr for StaticDirective {
294294
// * `foo[{bar,baz}]=trace`
295295
if let Some(maybe_fields) = split.next() {
296296
if split.next().is_some() {
297-
return Err(DirectiveParseError::msg(
297+
return Err(ParseError::msg(
298298
"too many '[{' in filter directive, expected 0 or 1",
299299
));
300300
}
301301

302-
let fields = maybe_fields.strip_suffix("}]").ok_or_else(|| {
303-
DirectiveParseError::msg("expected fields list to end with '}]'")
304-
})?;
302+
let fields = maybe_fields
303+
.strip_suffix("}]")
304+
.ok_or_else(|| ParseError::msg("expected fields list to end with '}]'"))?;
305305
field_names.extend(fields.split(',').filter_map(|s| {
306306
if s.is_empty() {
307307
None
@@ -339,21 +339,21 @@ impl FromStr for StaticDirective {
339339

340340
// === impl ParseError ===
341341

342-
impl DirectiveParseError {
342+
impl ParseError {
343343
pub(crate) fn new() -> Self {
344-
DirectiveParseError {
344+
ParseError {
345345
kind: ParseErrorKind::Other(None),
346346
}
347347
}
348348

349349
pub(crate) fn msg(s: &'static str) -> Self {
350-
DirectiveParseError {
350+
ParseError {
351351
kind: ParseErrorKind::Other(Some(s)),
352352
}
353353
}
354354
}
355355

356-
impl fmt::Display for DirectiveParseError {
356+
impl fmt::Display for ParseError {
357357
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
358358
match self.kind {
359359
ParseErrorKind::Other(None) => f.pad("invalid filter directive"),
@@ -364,7 +364,7 @@ impl fmt::Display for DirectiveParseError {
364364
}
365365
}
366366

367-
impl Error for DirectiveParseError {
367+
impl Error for ParseError {
368368
fn description(&self) -> &str {
369369
"invalid filter directive"
370370
}
@@ -378,15 +378,15 @@ impl Error for DirectiveParseError {
378378
}
379379
}
380380

381-
impl From<Box<dyn Error + Send + Sync>> for DirectiveParseError {
381+
impl From<Box<dyn Error + Send + Sync>> for ParseError {
382382
fn from(e: Box<dyn Error + Send + Sync>) -> Self {
383383
Self {
384384
kind: ParseErrorKind::Field(e),
385385
}
386386
}
387387
}
388388

389-
impl From<level::ParseError> for DirectiveParseError {
389+
impl From<level::ParseError> for ParseError {
390390
fn from(l: level::ParseError) -> Self {
391391
Self {
392392
kind: ParseErrorKind::Level(l),

tracing-subscriber/src/filter/env/directive.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::FilterVec;
2-
pub(crate) use crate::filter::directive::{DirectiveParseError, StaticDirective};
2+
pub(crate) use crate::filter::directive::{ParseError, StaticDirective};
33
use crate::filter::{
44
directive::{DirectiveSet, Match},
55
env::{field, FieldMap},
@@ -145,7 +145,7 @@ impl Match for Directive {
145145
}
146146

147147
impl FromStr for Directive {
148-
type Err = DirectiveParseError;
148+
type Err = ParseError;
149149
fn from_str(from: &str) -> Result<Self, Self::Err> {
150150
lazy_static! {
151151
static ref DIRECTIVE_RE: Regex = Regex::new(
@@ -183,9 +183,7 @@ impl FromStr for Directive {
183183
"#).unwrap();
184184
}
185185

186-
let caps = DIRECTIVE_RE
187-
.captures(from)
188-
.ok_or_else(DirectiveParseError::new)?;
186+
let caps = DIRECTIVE_RE.captures(from).ok_or_else(ParseError::new)?;
189187

190188
if let Some(level) = caps
191189
.name("global_level")

tracing-subscriber/src/filter/env/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
subscribe::{Context, Subscribe},
1414
sync::RwLock,
1515
};
16-
use directive::DirectiveParseError;
16+
use directive::ParseError;
1717
use std::{cell::RefCell, collections::HashMap, env, error::Error, fmt, str::FromStr};
1818
use tracing_core::{
1919
callsite,
@@ -133,7 +133,7 @@ pub struct FromEnvError {
133133

134134
#[derive(Debug)]
135135
enum ErrorKind {
136-
Parse(DirectiveParseError),
136+
Parse(ParseError),
137137
Env(env::VarError),
138138
}
139139

@@ -170,7 +170,7 @@ impl EnvFilter {
170170

171171
/// Returns a new `EnvFilter` from the directives in the given string,
172172
/// or an error if any are invalid.
173-
pub fn try_new<S: AsRef<str>>(dirs: S) -> Result<Self, directive::DirectiveParseError> {
173+
pub fn try_new<S: AsRef<str>>(dirs: S) -> Result<Self, directive::ParseError> {
174174
let directives = dirs
175175
.as_ref()
176176
.split(',')
@@ -488,7 +488,7 @@ impl<C: Collect> Subscribe<C> for EnvFilter {
488488
}
489489

490490
impl FromStr for EnvFilter {
491-
type Err = directive::DirectiveParseError;
491+
type Err = directive::ParseError;
492492

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

540540
// ===== impl FromEnvError =====
541541

542-
impl From<directive::DirectiveParseError> for FromEnvError {
543-
fn from(p: directive::DirectiveParseError) -> Self {
542+
impl From<directive::ParseError> for FromEnvError {
543+
fn from(p: directive::ParseError) -> Self {
544544
Self {
545545
kind: ErrorKind::Parse(p),
546546
}

tracing-subscriber/src/filter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod level;
1717
mod subscriber_filters;
1818
mod targets;
1919

20-
pub use self::directive::DirectiveParseError;
20+
pub use self::directive::ParseError;
2121
pub use self::filter_fn::*;
2222
#[cfg(not(feature = "registry"))]
2323
pub(crate) use self::has_plf_stubs::*;

tracing-subscriber/src/filter/targets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
filter::{
3-
directive::{DirectiveParseError, DirectiveSet, StaticDirective},
3+
directive::{DirectiveSet, ParseError, StaticDirective},
44
LevelFilter,
55
},
66
subscribe,
@@ -302,7 +302,7 @@ where
302302
}
303303

304304
impl FromStr for Targets {
305-
type Err = DirectiveParseError;
305+
type Err = ParseError;
306306
fn from_str(s: &str) -> Result<Self, Self::Err> {
307307
s.split(',')
308308
.map(StaticDirective::from_str)

0 commit comments

Comments
 (0)