From 5c2eeee1d21459a0536732d5cb7c2b17d5ed01ae Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Mon, 4 Nov 2019 15:21:00 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20panic=20on=20storage=20decode?= =?UTF-8?q?=20error=20(#30)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of panicking when the storage data reveived cannot be decoded we pass on the error. --- src/rpc.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/rpc.rs b/src/rpc.rs index 3e9fbedeb9..1cbd404713 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -86,10 +86,16 @@ impl Rpc { ) -> impl Future, Error = Error> { self.state .storage(key, None) - .map(|data| { - data.map(|d| Decode::decode(&mut &d.0[..]).expect("Valid storage key")) - }) .map_err(Into::into) + .and_then(|data| { + match data { + Some(data) => { + let value = Decode::decode(&mut &data.0[..])?; + Ok(Some(value)) + } + None => Ok(None), + } + }) } /// Fetch the genesis hash