mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 16:51:03 +00:00
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:
@@ -38,40 +38,52 @@ mod codes {
|
||||
}
|
||||
|
||||
/// errors encountered by background block authorship task
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// An error occurred while importing the block
|
||||
#[display(fmt = "Block import failed: {:?}", _0)]
|
||||
#[error("Block import failed: {0:?}")]
|
||||
BlockImportError(ImportResult),
|
||||
/// Transaction pool is empty, cannot create a block
|
||||
#[display(fmt = "Transaction pool is empty, set create_empty to true,\
|
||||
if you want to create empty blocks")]
|
||||
#[error(
|
||||
"Transaction pool is empty, set create_empty to true, if you want to create empty blocks"
|
||||
)]
|
||||
EmptyTransactionPool,
|
||||
/// encountered during creation of Proposer.
|
||||
#[display(fmt = "Consensus Error: {}", _0)]
|
||||
ConsensusError(ConsensusError),
|
||||
#[error("Consensus Error: {0}")]
|
||||
ConsensusError(#[from] ConsensusError),
|
||||
/// Failed to create Inherents data
|
||||
#[display(fmt = "Inherents Error: {}", _0)]
|
||||
InherentError(InherentsError),
|
||||
#[error("Inherents Error: {0}")]
|
||||
InherentError(#[from] InherentsError),
|
||||
/// error encountered during finalization
|
||||
#[display(fmt = "Finalization Error: {}", _0)]
|
||||
BlockchainError(BlockchainError),
|
||||
#[error("Finalization Error: {0}")]
|
||||
BlockchainError(#[from] BlockchainError),
|
||||
/// Supplied parent_hash doesn't exist in chain
|
||||
#[display(fmt = "Supplied parent_hash: {} doesn't exist in chain", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Supplied parent_hash: {0} doesn't exist in chain")]
|
||||
BlockNotFound(String),
|
||||
/// Some string error
|
||||
#[display(fmt = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
StringError(String),
|
||||
/// send error
|
||||
#[display(fmt = "Consensus process is terminating")]
|
||||
Canceled(oneshot::Canceled),
|
||||
#[error("Consensus process is terminating")]
|
||||
Canceled(#[from] oneshot::Canceled),
|
||||
/// send error
|
||||
#[display(fmt = "Consensus process is terminating")]
|
||||
SendError(SendError),
|
||||
#[error("Consensus process is terminating")]
|
||||
SendError(#[from] SendError),
|
||||
/// Some other error.
|
||||
#[display(fmt = "Other error: {}", _0)]
|
||||
Other(Box<dyn std::error::Error + Send>),
|
||||
#[error("Other error: {0}")]
|
||||
Other(#[from] Box<dyn std::error::Error + Send>),
|
||||
}
|
||||
|
||||
impl From<ImportResult> for Error {
|
||||
fn from(err: ImportResult) -> Self {
|
||||
Error::BlockImportError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Error {
|
||||
fn from(s: String) -> Self {
|
||||
Error::StringError(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error {
|
||||
|
||||
Reference in New Issue
Block a user