use thiserror instead of derive_more for error handling (#10696)

* use thiserror instead of derive_more for error handling

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Update utils/prometheus/src/lib.rs

* Update utils/prometheus/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Qinxuan Chen
2022-01-26 03:48:46 +08:00
committed by GitHub
parent 38d94d6323
commit e956c2e1c7
47 changed files with 378 additions and 357 deletions
+6 -13
View File
@@ -78,26 +78,19 @@ impl<TBlock: Block> PrettyPrinter<TBlock> for DebugPrinter {
}
/// Aggregated error for `Inspector` operations.
#[derive(Debug, derive_more::From, derive_more::Display)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// Could not decode Block or Extrinsic.
Codec(codec::Error),
#[error(transparent)]
Codec(#[from] codec::Error),
/// Error accessing blockchain DB.
Blockchain(sp_blockchain::Error),
#[error(transparent)]
Blockchain(#[from] sp_blockchain::Error),
/// Given block has not been found.
#[error("{0}")]
NotFound(String),
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Codec(ref e) => Some(e),
Self::Blockchain(ref e) => Some(e),
Self::NotFound(_) => None,
}
}
}
/// A helper trait to access block headers and bodies.
pub trait ChainAccess<TBlock: Block>: HeaderBackend<TBlock> + BlockBackend<TBlock> {}