Merge pull request #117 from fujiapple852/hotfix-display-stack-overflow

Fix recursive Display::fmt implementation on Error to avoid stack overflow
This commit is contained in:
Vincent Prouillet 2020-01-30 21:26:06 -08:00 committed by GitHub
commit aae977651c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -117,7 +117,7 @@ impl fmt::Display for Error {
| ErrorKind::ImmatureSignature
| ErrorKind::InvalidAlgorithm
| ErrorKind::InvalidKeyFormat
| ErrorKind::InvalidAlgorithmName => write!(f, "{}", self),
| ErrorKind::InvalidAlgorithmName => write!(f, "{:?}", self.0),
ErrorKind::Json(ref err) => write!(f, "JSON error: {}", err),
ErrorKind::Utf8(ref err) => write!(f, "UTF-8 error: {}", err),
ErrorKind::Crypto(ref err) => write!(f, "Crypto error: {}", err),
@ -162,3 +162,14 @@ impl From<ErrorKind> for Error {
new_error(kind)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_rendering() {
assert_eq!("InvalidAlgorithmName", Error::from(ErrorKind::InvalidAlgorithmName).to_string());
}
}