From b665db6510ccf7211f686f3eb0cd5caa34868e93 Mon Sep 17 00:00:00 2001 From: Web3 Philosopher <seunlanlege@gmail.com> Date: Thu, 6 Jul 2023 17:09:13 +0200 Subject: [PATCH] don't wrap errors (#2830) --- cumulus/client/network/src/tests.rs | 9 ++++++--- .../client/relay-chain-inprocess-interface/src/lib.rs | 9 ++++++--- cumulus/client/relay-chain-rpc-interface/src/lib.rs | 8 +++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cumulus/client/network/src/tests.rs b/cumulus/client/network/src/tests.rs index ce2246f04c9..d2def635b5c 100644 --- a/cumulus/client/network/src/tests.rs +++ b/cumulus/client/network/src/tests.rs @@ -242,9 +242,12 @@ impl RelayChainInterface for DummyRelayChainInterface { async fn header(&self, block_id: BlockId) -> RelayChainResult<Option<PHeader>> { let hash = match block_id { BlockId::Hash(hash) => hash, - BlockId::Number(num) => self.relay_client.hash(num)?.ok_or_else(|| { - RelayChainError::GenericError(format!("block with number {num} not found")) - })?, + BlockId::Number(num) => + if let Some(hash) = self.relay_client.hash(num)? { + hash + } else { + return Ok(None) + }, }; let header = self.relay_client.header(hash)?; diff --git a/cumulus/client/relay-chain-inprocess-interface/src/lib.rs b/cumulus/client/relay-chain-inprocess-interface/src/lib.rs index cc522ba4d3a..54b0362a475 100644 --- a/cumulus/client/relay-chain-inprocess-interface/src/lib.rs +++ b/cumulus/client/relay-chain-inprocess-interface/src/lib.rs @@ -94,9 +94,12 @@ impl RelayChainInterface for RelayChainInProcessInterface { async fn header(&self, block_id: BlockId) -> RelayChainResult<Option<PHeader>> { let hash = match block_id { BlockId::Hash(hash) => hash, - BlockId::Number(num) => self.full_client.hash(num)?.ok_or_else(|| { - RelayChainError::GenericError(format!("block with number {num} not found")) - })?, + BlockId::Number(num) => + if let Some(hash) = self.full_client.hash(num)? { + hash + } else { + return Ok(None) + }, }; let header = self.full_client.header(hash)?; diff --git a/cumulus/client/relay-chain-rpc-interface/src/lib.rs b/cumulus/client/relay-chain-rpc-interface/src/lib.rs index 3c6f3ca3232..964d47eff91 100644 --- a/cumulus/client/relay-chain-rpc-interface/src/lib.rs +++ b/cumulus/client/relay-chain-rpc-interface/src/lib.rs @@ -82,9 +82,11 @@ impl RelayChainInterface for RelayChainRpcInterface { let hash = match block_id { BlockId::Hash(hash) => hash, BlockId::Number(num) => - self.rpc_client.chain_get_block_hash(Some(num)).await?.ok_or_else(|| { - RelayChainError::GenericError(format!("block with number {num} not found")) - })?, + if let Some(hash) = self.rpc_client.chain_get_block_hash(Some(num)).await? { + hash + } else { + return Ok(None) + }, }; let header = self.rpc_client.chain_get_header(Some(hash)).await?; -- GitLab