Replace error-chain for client error (#2231)

* WIP: convert client error

* Remove error_chain for client error

* Ignore tx-pool error deprecation warning

* Update Cargo.lock files

* Fix tests

* Increment impl_version

* Derive From impls, remove allow(missing_docs)

* Remove space

* Remove redundant into()s

* Blockchain Error source

* Bump impl version
This commit is contained in:
Andrew Jones
2019-04-11 20:33:43 +01:00
committed by Bastian Köcher
parent 1e0c1d8850
commit 7f59cdb900
39 changed files with 298 additions and 290 deletions
@@ -20,7 +20,7 @@ use std::fmt::Debug;
use std::sync::Arc;
use parity_codec::{Encode, Decode};
use client::backend::AuxStore;
use client::error::{Result as ClientResult, Error as ClientError, ErrorKind as ClientErrorKind};
use client::error::{Result as ClientResult, Error as ClientError};
use fork_tree::ForkTree;
use grandpa::round::State as RoundState;
use runtime_primitives::traits::{Block as BlockT, NumberFor};
@@ -109,7 +109,7 @@ fn load_decode<B: AuxStore, T: Decode>(backend: &B, key: &[u8]) -> ClientResult<
None => Ok(None),
Some(t) => T::decode(&mut &t[..])
.ok_or_else(
|| ClientErrorKind::Backend(format!("GRANDPA DB is corrupted.")).into(),
|| ClientError::Backend(format!("GRANDPA DB is corrupted.")),
)
.map(Some)
}
@@ -314,8 +314,8 @@ pub(crate) fn load_persistent<Block: BlockT, B, G>(
set_state: set_state.into(),
});
}
},
Some(other) => return Err(ClientErrorKind::Backend(
}
Some(other) => return Err(ClientError::Backend(
format!("Unsupported GRANDPA DB version: {:?}", other)
).into()),
}
@@ -33,7 +33,7 @@ use grandpa::voter_set::VoterSet;
use client::{
blockchain::Backend as BlockchainBackend,
error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult},
error::{Error as ClientError, Result as ClientResult},
light::fetcher::RemoteCallRequest,
};
use parity_codec::{Encode, Decode};
@@ -73,7 +73,7 @@ pub fn prove_finality<Block: BlockT, B, G>(
// early-return if we sure that the block is NOT a part of canonical chain
let canonical_block = blockchain.expect_block_hash_from_id(&BlockId::Number(block_number))?;
if block != canonical_block {
return Err(ClientErrorKind::Backend(
return Err(ClientError::Backend(
"Cannot generate finality proof for non-canonical block".into()
).into());
}
@@ -111,7 +111,7 @@ pub fn prove_finality<Block: BlockT, B, G>(
}
}
Err(ClientErrorKind::Backend(
Err(ClientError::Backend(
"cannot find justification for finalized block".into()
).into())
}
@@ -156,16 +156,16 @@ fn do_check_finality_proof<Block: BlockT<Hash=H256>, C, J>(
{
// decode finality proof
let proof = FinalityProof::<Block::Header, J>::decode(&mut &remote_proof[..])
.ok_or_else(|| ClientErrorKind::BadJustification("failed to decode finality proof".into()))?;
.ok_or_else(|| ClientError::BadJustification("failed to decode finality proof".into()))?;
// check that the first header in finalization path is the block itself
{
let finalized_header = proof.finalization_path.first()
.ok_or_else(|| ClientError::from(ClientErrorKind::BadJustification(
.ok_or_else(|| ClientError::from(ClientError::BadJustification(
"finality proof: finalized path is empty".into()
)))?;
if *finalized_header.number() != block.0 || finalized_header.hash() != block.1 {
return Err(ClientErrorKind::BadJustification(
return Err(ClientError::BadJustification(
"finality proof: block is not a part of finalized path".into()
).into());
}
@@ -177,7 +177,7 @@ fn do_check_finality_proof<Block: BlockT<Hash=H256>, C, J>(
let finalized_header = proof.finalization_path.last()
.expect("checked above that proof.finalization_path is not empty; qed");
if *finalized_header.number() != just_block.0 || finalized_header.hash() != just_block.1 {
return Err(ClientErrorKind::BadJustification(
return Err(ClientError::BadJustification(
"finality proof: target justification block is not a part of finalized path".into()
).into());
}
@@ -192,7 +192,7 @@ fn do_check_finality_proof<Block: BlockT<Hash=H256>, C, J>(
retry_count: None,
})?;
let grandpa_authorities: Vec<(AuthorityId, u64)> = Decode::decode(&mut &grandpa_authorities[..])
.ok_or_else(|| ClientErrorKind::BadJustification("failed to decode GRANDPA authorities set proof".into()))?;
.ok_or_else(|| ClientError::BadJustification("failed to decode GRANDPA authorities set proof".into()))?;
// and now check justification
proof.justification.verify(set_id, &grandpa_authorities.into_iter().collect())?;
@@ -392,7 +392,7 @@ mod tests {
fn target_block(&self) -> (u64, H256) { (3, header(3).hash()) }
fn verify(&self, _set_id: u64, _authorities: &VoterSet<AuthorityId>) -> ClientResult<()> {
Err(ClientErrorKind::Backend("test error".into()).into())
Err(ClientError::Backend("test error".into()))
}
}
@@ -19,7 +19,7 @@ use std::collections::{HashMap, HashSet};
use client::{CallExecutor, Client};
use client::backend::Backend;
use client::blockchain::HeaderBackend;
use client::error::{Error as ClientError, ErrorKind as ClientErrorKind};
use client::error::Error as ClientError;
use parity_codec::{Encode, Decode};
use grandpa::voter_set::VoterSet;
use grandpa::{Error as GrandpaError};
@@ -64,7 +64,7 @@ impl<Block: BlockT<Hash=H256>> GrandpaJustification<Block> {
let error = || {
let msg = "invalid precommits for target commit".to_string();
Err(Error::Client(ClientErrorKind::BadJustification(msg).into()))
Err(Error::Client(ClientError::BadJustification(msg)))
};
for signed in commit.precommits.iter() {
@@ -104,12 +104,12 @@ impl<Block: BlockT<Hash=H256>> GrandpaJustification<Block> {
{
let justification = GrandpaJustification::<Block>::decode(&mut &*encoded).ok_or_else(|| {
let msg = "failed to decode grandpa justification".to_string();
ClientError::from(ClientErrorKind::BadJustification(msg))
ClientError::from(ClientError::BadJustification(msg))
})?;
if (justification.commit.target_hash, justification.commit.target_number) != finalized_target {
let msg = "invalid commit target in grandpa justification".to_string();
Err(ClientErrorKind::BadJustification(msg).into())
Err(ClientError::BadJustification(msg))
} else {
justification.verify(set_id, voters).map(|_| justification)
}
@@ -132,7 +132,7 @@ impl<Block: BlockT<Hash=H256>> GrandpaJustification<Block> {
Ok(ref result) if result.ghost().is_some() => {},
_ => {
let msg = "invalid commit in grandpa justification".to_string();
return Err(ClientErrorKind::BadJustification(msg).into());
return Err(ClientError::BadJustification(msg));
}
}
@@ -145,7 +145,7 @@ impl<Block: BlockT<Hash=H256>> GrandpaJustification<Block> {
self.round,
set_id,
) {
return Err(ClientErrorKind::BadJustification(
return Err(ClientError::BadJustification(
"invalid signature for precommit in grandpa justification".to_string()).into());
}
@@ -162,7 +162,7 @@ impl<Block: BlockT<Hash=H256>> GrandpaJustification<Block> {
}
},
_ => {
return Err(ClientErrorKind::BadJustification(
return Err(ClientError::BadJustification(
"invalid precommit ancestry proof in grandpa justification".to_string()).into());
},
}
@@ -174,7 +174,7 @@ impl<Block: BlockT<Hash=H256>> GrandpaJustification<Block> {
.collect();
if visited_hashes != ancestry_hashes {
return Err(ClientErrorKind::BadJustification(
return Err(ClientError::BadJustification(
"invalid precommit ancestries in grandpa justification with unused headers".to_string()).into());
}