1
Fork 0

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.
This commit is contained in:
Sean McArthur 2019-05-16 17:09:04 -07:00
parent 7d5aa43325
commit d2d89b10de

View file

@ -300,7 +300,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 {
@ -313,6 +312,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))
}
}