Skip to content

Commit 29f8bad

Browse files
Thomas Scholtesascjones
Thomas Scholtes
authored andcommitted
Don’t panic on storage decode error (paritytech#30)
Instead of panicking when the storage data reveived cannot be decoded we pass on the error.
1 parent 90eaf32 commit 29f8bad

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/rpc.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,16 @@ impl<T: System> Rpc<T> {
8686
) -> impl Future<Item = Option<V>, Error = Error> {
8787
self.state
8888
.storage(key, None)
89-
.map(|data| {
90-
data.map(|d| Decode::decode(&mut &d.0[..]).expect("Valid storage key"))
91-
})
9289
.map_err(Into::into)
90+
.and_then(|data| {
91+
match data {
92+
Some(data) => {
93+
let value = Decode::decode(&mut &data.0[..])?;
94+
Ok(Some(value))
95+
}
96+
None => Ok(None),
97+
}
98+
})
9399
}
94100

95101
/// Fetch the genesis hash

0 commit comments

Comments
 (0)