mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 08:51:09 +00:00
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:
committed by
Bastian Köcher
parent
1e0c1d8850
commit
7f59cdb900
+3
-3
@@ -43,7 +43,7 @@ use std::collections::BTreeSet;
|
||||
|
||||
use log::warn;
|
||||
|
||||
use client::error::{ErrorKind as ClientErrorKind, Result as ClientResult};
|
||||
use client::error::{Error as ClientError, Result as ClientResult};
|
||||
use runtime_primitives::traits::{Block as BlockT, NumberFor, As, Zero};
|
||||
|
||||
use crate::cache::{CacheItemT, ComplexBlockId};
|
||||
@@ -537,10 +537,10 @@ mod chain {
|
||||
) -> ClientResult<bool> {
|
||||
let (begin, end) = if block1 > block2 { (block2, block1) } else { (block1, block2) };
|
||||
let mut current = storage.read_header(&end.hash)?
|
||||
.ok_or_else(|| ClientErrorKind::UnknownBlock(format!("{}", end.hash)))?;
|
||||
.ok_or_else(|| ClientError::UnknownBlock(format!("{}", end.hash)))?;
|
||||
while *current.number() > begin.number {
|
||||
current = storage.read_header(current.parent_hash())?
|
||||
.ok_or_else(|| ClientErrorKind::UnknownBlock(format!("{}", current.parent_hash())))?;
|
||||
.ok_or_else(|| ClientError::UnknownBlock(format!("{}", current.parent_hash())))?;
|
||||
}
|
||||
|
||||
Ok(begin.hash == current.hash())
|
||||
|
||||
+9
-9
@@ -20,7 +20,7 @@ use std::sync::Arc;
|
||||
|
||||
use kvdb::{KeyValueDB, DBTransaction};
|
||||
|
||||
use client::error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult};
|
||||
use client::error::{Error as ClientError, Result as ClientResult};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor};
|
||||
@@ -59,7 +59,7 @@ pub trait Storage<Block: BlockT, T: CacheItemT> {
|
||||
self.read_entry(at)
|
||||
.and_then(|entry| entry
|
||||
.ok_or_else(|| ClientError::from(
|
||||
ClientErrorKind::Backend(format!("Referenced cache entry at {:?} is not found", at)))))
|
||||
ClientError::Backend(format!("Referenced cache entry at {:?} is not found", at)))))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ impl<Block: BlockT, T: CacheItemT> Storage<Block, T> for DbStorage {
|
||||
.map_err(db_err)
|
||||
.and_then(|entry| match entry {
|
||||
Some(entry) => StorageEntry::<Block, T>::decode(&mut &entry[..])
|
||||
.ok_or_else(|| ClientErrorKind::Backend("Failed to decode cache entry".into()).into())
|
||||
.ok_or_else(|| ClientError::Backend("Failed to decode cache entry".into()))
|
||||
.map(Some),
|
||||
None => Ok(None),
|
||||
})
|
||||
@@ -236,9 +236,9 @@ mod meta {
|
||||
pub fn decode<Block: BlockT>(encoded: &[u8]) -> ClientResult<Metadata<Block>> {
|
||||
let input = &mut &*encoded;
|
||||
let finalized: Option<ComplexBlockId<Block>> = Decode::decode(input)
|
||||
.ok_or_else(|| ClientError::from(ClientErrorKind::Backend("Error decoding cache meta".into())))?;
|
||||
.ok_or_else(|| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?;
|
||||
let unfinalized: Vec<ComplexBlockId<Block>> = Decode::decode(input)
|
||||
.ok_or_else(|| ClientError::from(ClientErrorKind::Backend("Error decoding cache meta".into())))?;
|
||||
.ok_or_else(|| ClientError::from(ClientError::Backend("Error decoding cache meta".into())))?;
|
||||
|
||||
Ok(Metadata { finalized, unfinalized })
|
||||
}
|
||||
@@ -253,19 +253,19 @@ pub mod tests {
|
||||
|
||||
impl<Block: BlockT, T: CacheItemT> Storage<Block, T> for FaultyStorage {
|
||||
fn read_id(&self, _at: NumberFor<Block>) -> ClientResult<Option<Block::Hash>> {
|
||||
Err(ClientErrorKind::Backend("TestError".into()).into())
|
||||
Err(ClientError::Backend("TestError".into()))
|
||||
}
|
||||
|
||||
fn read_header(&self, _at: &Block::Hash) -> ClientResult<Option<Block::Header>> {
|
||||
Err(ClientErrorKind::Backend("TestError".into()).into())
|
||||
Err(ClientError::Backend("TestError".into()))
|
||||
}
|
||||
|
||||
fn read_meta(&self) -> ClientResult<Metadata<Block>> {
|
||||
Err(ClientErrorKind::Backend("TestError".into()).into())
|
||||
Err(ClientError::Backend("TestError".into()))
|
||||
}
|
||||
|
||||
fn read_entry(&self, _at: &ComplexBlockId<Block>) -> ClientResult<Option<StorageEntry<Block, T>>> {
|
||||
Err(ClientErrorKind::Backend("TestError".into()).into())
|
||||
Err(ClientError::Backend("TestError".into()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ impl<Block: BlockT> client::blockchain::Backend<Block> for BlockchainDb<Block> {
|
||||
match read_db(&*self.db, columns::KEY_LOOKUP, columns::BODY, id)? {
|
||||
Some(body) => match Decode::decode(&mut &body[..]) {
|
||||
Some(body) => Ok(Some(body)),
|
||||
None => return Err(client::error::ErrorKind::Backend("Error decoding body".into()).into()),
|
||||
None => return Err(client::error::Error::Backend("Error decoding body".into())),
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
@@ -235,7 +235,7 @@ impl<Block: BlockT> client::blockchain::Backend<Block> for BlockchainDb<Block> {
|
||||
match read_db(&*self.db, columns::KEY_LOOKUP, columns::JUSTIFICATION, id)? {
|
||||
Some(justification) => match Decode::decode(&mut &justification[..]) {
|
||||
Some(justification) => Ok(Some(justification)),
|
||||
None => return Err(client::error::ErrorKind::Backend("Error decoding justification".into()).into()),
|
||||
None => return Err(client::error::Error::Backend("Error decoding justification".into())),
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
@@ -326,14 +326,14 @@ where Block: BlockT<Hash=H256>,
|
||||
fn reset_storage(&mut self, mut top: StorageOverlay, children: ChildrenStorageOverlay) -> Result<H256, client::error::Error> {
|
||||
|
||||
if top.iter().any(|(k, _)| well_known_keys::is_child_storage_key(k)) {
|
||||
return Err(client::error::ErrorKind::GenesisInvalid.into());
|
||||
return Err(client::error::Error::GenesisInvalid.into());
|
||||
}
|
||||
|
||||
let mut transaction: PrefixedMemoryDB<Blake2Hasher> = Default::default();
|
||||
|
||||
for (child_key, child_map) in children {
|
||||
if !well_known_keys::is_child_storage_key(&child_key) {
|
||||
return Err(client::error::ErrorKind::GenesisInvalid.into());
|
||||
return Err(client::error::Error::GenesisInvalid.into());
|
||||
}
|
||||
|
||||
let (root, is_default, update) = self.old_state.child_storage_root(&child_key, child_map.into_iter().map(|(k, v)| (k, Some(v))));
|
||||
@@ -684,7 +684,7 @@ impl<Block: BlockT<Hash=H256>> Backend<Block> {
|
||||
(&r.number, &r.hash)
|
||||
);
|
||||
|
||||
return Err(::client::error::ErrorKind::NotInFinalizedChain.into());
|
||||
return Err(::client::error::Error::NotInFinalizedChain.into());
|
||||
}
|
||||
|
||||
retracted.push(r.hash.clone());
|
||||
@@ -726,7 +726,7 @@ impl<Block: BlockT<Hash=H256>> Backend<Block> {
|
||||
) -> Result<(), client::error::Error> {
|
||||
let last_finalized = last_finalized.unwrap_or_else(|| self.blockchain.meta.read().finalized_hash);
|
||||
if *header.parent_hash() != last_finalized {
|
||||
return Err(::client::error::ErrorKind::NonSequentialFinalization(
|
||||
return Err(::client::error::Error::NonSequentialFinalization(
|
||||
format!("Last finalized {:?} not parent of {:?}", last_finalized, header.hash()),
|
||||
).into());
|
||||
}
|
||||
@@ -926,7 +926,7 @@ impl<Block: BlockT<Hash=H256>> Backend<Block> {
|
||||
(number.clone(), hash.clone())
|
||||
)?;
|
||||
} else {
|
||||
return Err(client::error::ErrorKind::UnknownBlock(format!("Cannot set head {:?}", set_head)).into())
|
||||
return Err(client::error::Error::UnknownBlock(format!("Cannot set head {:?}", set_head)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1138,12 +1138,12 @@ impl<Block> client::backend::Backend<Block, Blake2Hasher> for Backend<Block> whe
|
||||
Some(commit) => {
|
||||
apply_state_commit(&mut transaction, commit);
|
||||
let removed = self.blockchain.header(BlockId::Number(best))?.ok_or_else(
|
||||
|| client::error::ErrorKind::UnknownBlock(
|
||||
|| client::error::Error::UnknownBlock(
|
||||
format!("Error reverting to {}. Block hash not found.", best)))?;
|
||||
|
||||
best -= As::sa(1); // prev block
|
||||
let hash = self.blockchain.hash(best)?.ok_or_else(
|
||||
|| client::error::ErrorKind::UnknownBlock(
|
||||
|| client::error::Error::UnknownBlock(
|
||||
format!("Error reverting to {}. Block hash not found.", best)))?;
|
||||
let key = utils::number_and_hash_to_lookup_key(best.clone(), &hash);
|
||||
transaction.put(columns::META, meta_keys::BEST_BLOCK, &key);
|
||||
@@ -1185,10 +1185,10 @@ impl<Block> client::backend::Backend<Block, Blake2Hasher> for Backend<Block> whe
|
||||
let state = DbState::new(self.storage.clone(), root);
|
||||
Ok(CachingState::new(state, self.shared_cache.clone(), Some(hash)))
|
||||
} else {
|
||||
Err(client::error::ErrorKind::UnknownBlock(format!("State already discarded for {:?}", block)).into())
|
||||
Err(client::error::Error::UnknownBlock(format!("State already discarded for {:?}", block)))
|
||||
}
|
||||
},
|
||||
Ok(None) => Err(client::error::ErrorKind::UnknownBlock(format!("Unknown state for block {:?}", block)).into()),
|
||||
Ok(None) => Err(client::error::Error::UnknownBlock(format!("Unknown state for block {:?}", block))),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ use client::blockchain::{BlockStatus, Cache as BlockchainCache,
|
||||
HeaderBackend as BlockchainHeaderBackend, Info as BlockchainInfo};
|
||||
use client::cht;
|
||||
use client::leaves::{LeafSet, FinalizationDisplaced};
|
||||
use client::error::{ErrorKind as ClientErrorKind, Result as ClientResult};
|
||||
use client::error::{Error as ClientError, Result as ClientResult};
|
||||
use client::light::blockchain::Storage as LightBlockchainStorage;
|
||||
use parity_codec::{Decode, Encode};
|
||||
use primitives::Blake2Hasher;
|
||||
@@ -256,7 +256,7 @@ impl<Block: BlockT> LightStorage<Block> {
|
||||
) -> ClientResult<()> {
|
||||
let meta = self.meta.read();
|
||||
if &meta.finalized_hash != header.parent_hash() {
|
||||
return Err(::client::error::ErrorKind::NonSequentialFinalization(
|
||||
return Err(::client::error::Error::NonSequentialFinalization(
|
||||
format!("Last finalized {:?} not parent of {:?}",
|
||||
meta.finalized_hash, hash),
|
||||
).into())
|
||||
@@ -330,7 +330,7 @@ impl<Block: BlockT> LightStorage<Block> {
|
||||
cht_size: u64,
|
||||
block: NumberFor<Block>
|
||||
) -> ClientResult<Block::Hash> {
|
||||
let no_cht_for_block = || ClientErrorKind::Backend(format!("CHT for block {} not exists", block)).into();
|
||||
let no_cht_for_block = || ClientError::Backend(format!("CHT for block {} not exists", block));
|
||||
|
||||
let cht_number = cht::block_to_cht_number(cht_size, block).ok_or_else(no_cht_for_block)?;
|
||||
let cht_start = cht::start_number(cht_size, cht_number);
|
||||
@@ -474,7 +474,7 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
|
||||
self.db.write(transaction).map_err(db_err)?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ClientErrorKind::UnknownBlock(format!("Cannot set head {:?}", id)).into())
|
||||
Err(ClientError::UnknownBlock(format!("Cannot set head {:?}", id)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,7 +514,7 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ClientErrorKind::UnknownBlock(format!("Cannot finalize block {:?}", id)).into())
|
||||
Err(ClientError::UnknownBlock(format!("Cannot finalize block {:?}", id)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ pub fn number_and_hash_to_lookup_key<N, H>(number: N, hash: H) -> Vec<u8> where
|
||||
/// all block lookup keys start with the block number.
|
||||
pub fn lookup_key_to_number<N>(key: &[u8]) -> client::error::Result<N> where N: As<u64> {
|
||||
if key.len() < 4 {
|
||||
return Err(client::error::ErrorKind::Backend("Invalid block key".into()).into());
|
||||
return Err(client::error::Error::Backend("Invalid block key".into()));
|
||||
}
|
||||
Ok((key[0] as u64) << 24
|
||||
| (key[1] as u64) << 16
|
||||
@@ -187,21 +187,21 @@ pub fn block_id_to_lookup_key<Block>(
|
||||
/// Maps database error to client error
|
||||
pub fn db_err(err: io::Error) -> client::error::Error {
|
||||
use std::error::Error;
|
||||
client::error::ErrorKind::Backend(err.description().into()).into()
|
||||
client::error::Error::Backend(err.description().into())
|
||||
}
|
||||
|
||||
/// Open RocksDB database.
|
||||
pub fn open_database(config: &DatabaseSettings, col_meta: Option<u32>, db_type: &str) -> client::error::Result<Arc<KeyValueDB>> {
|
||||
let mut db_config = DatabaseConfig::with_columns(Some(NUM_COLUMNS));
|
||||
db_config.memory_budget = config.cache_size;
|
||||
let path = config.path.to_str().ok_or_else(|| client::error::ErrorKind::Backend("Invalid database path".into()))?;
|
||||
let path = config.path.to_str().ok_or_else(|| client::error::Error::Backend("Invalid database path".into()))?;
|
||||
let db = Database::open(&db_config, &path).map_err(db_err)?;
|
||||
|
||||
// check database type
|
||||
match db.get(col_meta, meta_keys::TYPE).map_err(db_err)? {
|
||||
Some(stored_type) => {
|
||||
if db_type.as_bytes() != &*stored_type {
|
||||
return Err(client::error::ErrorKind::Backend(
|
||||
return Err(client::error::Error::Backend(
|
||||
format!("Unexpected database type. Expected: {}", db_type)).into());
|
||||
}
|
||||
},
|
||||
@@ -237,7 +237,7 @@ pub fn read_header<Block: BlockT>(
|
||||
Some(header) => match Block::Header::decode(&mut &header[..]) {
|
||||
Some(header) => Ok(Some(header)),
|
||||
None => return Err(
|
||||
client::error::ErrorKind::Backend("Error decoding header".into()).into()
|
||||
client::error::Error::Backend("Error decoding header".into())
|
||||
),
|
||||
}
|
||||
None => Ok(None),
|
||||
@@ -252,7 +252,7 @@ pub fn require_header<Block: BlockT>(
|
||||
id: BlockId<Block>,
|
||||
) -> client::error::Result<Block::Header> {
|
||||
read_header(db, col_index, col, id)
|
||||
.and_then(|header| header.ok_or_else(|| client::error::ErrorKind::UnknownBlock(format!("{}", id)).into()))
|
||||
.and_then(|header| header.ok_or_else(|| client::error::Error::UnknownBlock(format!("{}", id))))
|
||||
}
|
||||
|
||||
/// Read meta from the database.
|
||||
@@ -266,7 +266,7 @@ pub fn read_meta<Block>(db: &KeyValueDB, col_meta: Option<u32>, col_header: Opti
|
||||
let genesis_hash: Block::Hash = match db.get(col_meta, meta_keys::GENESIS_HASH).map_err(db_err)? {
|
||||
Some(h) => match Decode::decode(&mut &h[..]) {
|
||||
Some(h) => h,
|
||||
None => return Err(client::error::ErrorKind::Backend("Error decoding genesis hash".into()).into()),
|
||||
None => return Err(client::error::Error::Backend("Error decoding genesis hash".into())),
|
||||
},
|
||||
None => return Ok(Meta {
|
||||
best_hash: Default::default(),
|
||||
|
||||
Reference in New Issue
Block a user