Skip to content

Commit 3e815b7

Browse files
committed
Merge #400: Improved error handling in Parity serde impl
662843e Improved error handling in `Parity` serde impl (Martin Habovstiak) Pull request description: * Fixes error message to be according to the trait documentation * Uses `unexpected_value` to provide more information about the error ACKs for top commit: apoelstra: ACK 662843e Tree-SHA512: 2506f06305b01793f64818640931d00564334d96a1e0ef00574faacf1ec8733da13fbf91e57e49fa7c9c06587863fe66145f25afae8d8cabe546dd0ecc48caea
2 parents 8bf2927 + 662843e commit 3e815b7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/key.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,13 +1292,16 @@ impl<'de> ::serde::Deserialize<'de> for Parity {
12921292
type Value = Parity;
12931293

12941294
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1295-
formatter.write_str("Expecting a 4 byte int i32")
1295+
formatter.write_str("32-bit integer with value 0 or 1")
12961296
}
12971297

12981298
fn visit_i32<E>(self, v: i32) -> Result<Self::Value, E>
12991299
where E: ::serde::de::Error
13001300
{
1301-
Parity::from_i32(v).map_err(E::custom)
1301+
use serde::de::Unexpected;
1302+
1303+
Parity::from_i32(v)
1304+
.map_err(|_| E::invalid_value(Unexpected::Signed(v.into()), &"0 or 1"))
13021305
}
13031306
}
13041307

0 commit comments

Comments
 (0)