Skip to content

Commit

Permalink
Rollup merge of rust-lang#60897 - seanmonstar:patch-4, r=sfackler
Browse files Browse the repository at this point in the history
error: remove StringError from Debug output

Seeing `StringError("something something")` in debug output can cause
 someone to think there was an error dealing with `String`s, not that the
error type is just a string. So, remove that noise.

For example:

```
io error: Custom { kind: InvalidData, error: StringError("corrupt data") }
```

With this change:

```
io error: Custom { kind: InvalidData, error: "corrupt data" }
```
  • Loading branch information
Centril authored May 30, 2019
2 parents 0bfbaa6 + d2d89b1 commit f6da6b0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ impl From<String> for Box<dyn Error + Send + Sync> {
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
/// ```
fn from(err: String) -> Box<dyn Error + Send + Sync> {
#[derive(Debug)]
struct StringError(String);

impl Error for StringError {
Expand All @@ -327,6 +326,13 @@ impl From<String> for Box<dyn Error + Send + Sync> {
}
}

// Purposefully skip printing "StringError(..)"
impl Debug for StringError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Debug::fmt(&self.0, f)
}
}

Box::new(StringError(err))
}
}
Expand Down

0 comments on commit f6da6b0

Please sign in to comment.