Rollup merge of #60897 - seanmonstar:patch-4, r=sfackler
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" } ```
This commit is contained in:
commit
eebe62aaa1
@ -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 {
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user