- Fix recursive `Display::fmt` implementation on `Error` to avoid stack overflow
- Added unit test to cover a sample case
This commit is contained in:
parent
e89fa41b7a
commit
2f359b515c
|
@ -117,7 +117,7 @@ impl fmt::Display for Error {
|
||||||
| ErrorKind::ImmatureSignature
|
| ErrorKind::ImmatureSignature
|
||||||
| ErrorKind::InvalidAlgorithm
|
| ErrorKind::InvalidAlgorithm
|
||||||
| ErrorKind::InvalidKeyFormat
|
| ErrorKind::InvalidKeyFormat
|
||||||
| ErrorKind::InvalidAlgorithmName => write!(f, "{}", self),
|
| ErrorKind::InvalidAlgorithmName => write!(f, "{:?}", self.0),
|
||||||
ErrorKind::Json(ref err) => write!(f, "JSON error: {}", err),
|
ErrorKind::Json(ref err) => write!(f, "JSON error: {}", err),
|
||||||
ErrorKind::Utf8(ref err) => write!(f, "UTF-8 error: {}", err),
|
ErrorKind::Utf8(ref err) => write!(f, "UTF-8 error: {}", err),
|
||||||
ErrorKind::Crypto(ref err) => write!(f, "Crypto error: {}", err),
|
ErrorKind::Crypto(ref err) => write!(f, "Crypto error: {}", err),
|
||||||
|
@ -162,3 +162,14 @@ impl From<ErrorKind> for Error {
|
||||||
new_error(kind)
|
new_error(kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_error_rendering() {
|
||||||
|
assert_eq!("InvalidAlgorithmName", Error::from(ErrorKind::InvalidAlgorithmName).to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue