Handle RLP to string UTF-8 decoding errors (#2217)

This commit is contained in:
Arkadiy Paronyan 2016-09-21 18:59:46 +08:00 committed by Gav Wood
parent a100b9d09e
commit 0688716af6
1 changed files with 3 additions and 1 deletions

View File

@ -174,6 +174,8 @@ pub enum FromBytesError {
DataIsTooLong,
/// Integer-representation is non-canonically prefixed with zero byte(s).
ZeroPrefixedInt,
/// String representation is not utf-8
InvalidUtf8,
}
impl StdError for FromBytesError {
@ -199,7 +201,7 @@ pub trait FromBytes: Sized {
impl FromBytes for String {
fn from_bytes(bytes: &[u8]) -> FromBytesResult<String> {
Ok(::std::str::from_utf8(bytes).unwrap().to_owned())
::std::str::from_utf8(bytes).map(|s| s.to_owned()).map_err(|_| FromBytesError::InvalidUtf8)
}
}