mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
error rework, for polkadot convenience (#7446)
Co-authored-by: Bernhard Schuster <bernhard@parity.io> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1679919830
commit
9687759774
@@ -17,142 +17,142 @@
|
||||
|
||||
//! Substrate client possible errors.
|
||||
|
||||
use std::{self, error, result};
|
||||
use std::{self, result};
|
||||
use sp_state_machine;
|
||||
use sp_runtime::transaction_validity::TransactionValidityError;
|
||||
use sp_consensus;
|
||||
use derive_more::{Display, From};
|
||||
use codec::Error as CodecError;
|
||||
|
||||
/// Client Result type alias
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
/// Error when the runtime failed to apply an extrinsic.
|
||||
#[derive(Debug, Display)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ApplyExtrinsicFailed {
|
||||
/// The transaction cannot be included into the current block.
|
||||
///
|
||||
/// This doesn't necessary mean that the transaction itself is invalid, but it might be just
|
||||
/// unappliable onto the current block.
|
||||
#[display(fmt = "Extrinsic is not valid: {:?}", _0)]
|
||||
Validity(TransactionValidityError),
|
||||
#[error("Extrinsic is not valid: {0:?}")]
|
||||
Validity(#[from] TransactionValidityError),
|
||||
/// This is used for miscellaneous errors that can be represented by string and not handleable.
|
||||
///
|
||||
/// This will become obsolete with complete migration to v4 APIs.
|
||||
#[display(fmt = "Extrinsic failed: {:?}", _0)]
|
||||
#[error("Extrinsic failed: {0}")]
|
||||
Msg(String),
|
||||
}
|
||||
|
||||
/// Substrate Client error
|
||||
#[derive(Debug, Display, From)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// Consensus Error
|
||||
#[display(fmt = "Consensus: {}", _0)]
|
||||
Consensus(sp_consensus::Error),
|
||||
#[error(transparent)]
|
||||
Consensus(#[from] sp_consensus::Error),
|
||||
/// Backend error.
|
||||
#[display(fmt = "Backend error: {}", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Backend error: {0}")]
|
||||
Backend(String),
|
||||
/// Unknown block.
|
||||
#[display(fmt = "UnknownBlock: {}", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("UnknownBlock: {0}")]
|
||||
UnknownBlock(String),
|
||||
/// The `apply_extrinsic` is not valid due to the given `TransactionValidityError`.
|
||||
#[display(fmt = "{:?}", _0)]
|
||||
ApplyExtrinsicFailed(ApplyExtrinsicFailed),
|
||||
#[error(transparent)]
|
||||
ApplyExtrinsicFailed(#[from] ApplyExtrinsicFailed),
|
||||
/// Execution error.
|
||||
#[display(fmt = "Execution: {}", _0)]
|
||||
#[error("Execution failed: {0:?}")]
|
||||
Execution(Box<dyn sp_state_machine::Error>),
|
||||
/// Blockchain error.
|
||||
#[display(fmt = "Blockchain: {}", _0)]
|
||||
Blockchain(Box<Error>),
|
||||
#[error("Blockchain")]
|
||||
Blockchain(#[source] Box<Error>),
|
||||
/// Invalid authorities set received from the runtime.
|
||||
#[display(fmt = "Current state of blockchain has invalid authorities set")]
|
||||
#[error("Current state of blockchain has invalid authorities set")]
|
||||
InvalidAuthoritiesSet,
|
||||
/// Could not get runtime version.
|
||||
#[display(fmt = "Failed to get runtime version: {}", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Failed to get runtime version: {0}")]
|
||||
VersionInvalid(String),
|
||||
/// Genesis config is invalid.
|
||||
#[display(fmt = "Genesis config provided is invalid")]
|
||||
#[error("Genesis config provided is invalid")]
|
||||
GenesisInvalid,
|
||||
/// Error decoding header justification.
|
||||
#[display(fmt = "error decoding justification for header")]
|
||||
#[error("error decoding justification for header")]
|
||||
JustificationDecode,
|
||||
/// Justification for header is correctly encoded, but invalid.
|
||||
#[display(fmt = "bad justification for header: {}", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("bad justification for header: {0}")]
|
||||
BadJustification(String),
|
||||
/// Not available on light client.
|
||||
#[display(fmt = "This method is not currently available when running in light client mode")]
|
||||
#[error("This method is not currently available when running in light client mode")]
|
||||
NotAvailableOnLightClient,
|
||||
/// Invalid remote CHT-based proof.
|
||||
#[display(fmt = "Remote node has responded with invalid header proof")]
|
||||
#[error("Remote node has responded with invalid header proof")]
|
||||
InvalidCHTProof,
|
||||
/// Remote fetch has been cancelled.
|
||||
#[display(fmt = "Remote data fetch has been cancelled")]
|
||||
#[error("Remote data fetch has been cancelled")]
|
||||
RemoteFetchCancelled,
|
||||
/// Remote fetch has been failed.
|
||||
#[display(fmt = "Remote data fetch has been failed")]
|
||||
#[error("Remote data fetch has been failed")]
|
||||
RemoteFetchFailed,
|
||||
/// Error decoding call result.
|
||||
#[display(fmt = "Error decoding call result of {}: {}", _0, _1)]
|
||||
CallResultDecode(&'static str, CodecError),
|
||||
#[error("Error decoding call result of {0}")]
|
||||
CallResultDecode(&'static str, #[source] CodecError),
|
||||
/// Error converting a parameter between runtime and node.
|
||||
#[display(fmt = "Error converting `{}` between runtime and node", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Error converting `{0}` between runtime and node")]
|
||||
RuntimeParamConversion(String),
|
||||
/// Changes tries are not supported.
|
||||
#[display(fmt = "Changes tries are not supported by the runtime")]
|
||||
#[error("Changes tries are not supported by the runtime")]
|
||||
ChangesTriesNotSupported,
|
||||
/// Error reading changes tries configuration.
|
||||
#[display(fmt = "Error reading changes tries configuration")]
|
||||
#[error("Error reading changes tries configuration")]
|
||||
ErrorReadingChangesTriesConfig,
|
||||
/// Key changes query has failed.
|
||||
#[display(fmt = "Failed to check changes proof: {}", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Failed to check changes proof: {0}")]
|
||||
ChangesTrieAccessFailed(String),
|
||||
/// Last finalized block not parent of current.
|
||||
#[display(fmt = "Did not finalize blocks in sequential order.")]
|
||||
#[from(ignore)]
|
||||
#[error("Did not finalize blocks in sequential order.")]
|
||||
NonSequentialFinalization(String),
|
||||
/// Safety violation: new best block not descendent of last finalized.
|
||||
#[display(fmt = "Potential long-range attack: block not in finalized chain.")]
|
||||
#[error("Potential long-range attack: block not in finalized chain.")]
|
||||
NotInFinalizedChain,
|
||||
/// Hash that is required for building CHT is missing.
|
||||
#[display(fmt = "Failed to get hash of block for building CHT")]
|
||||
#[error("Failed to get hash of block for building CHT")]
|
||||
MissingHashRequiredForCHT,
|
||||
/// Invalid calculated state root on block import.
|
||||
#[display(fmt = "Calculated state root does not match.")]
|
||||
#[error("Calculated state root does not match.")]
|
||||
InvalidStateRoot,
|
||||
/// Incomplete block import pipeline.
|
||||
#[display(fmt = "Incomplete block import pipeline.")]
|
||||
#[error("Incomplete block import pipeline.")]
|
||||
IncompletePipeline,
|
||||
#[display(fmt = "Transaction pool not ready for block production.")]
|
||||
#[error("Transaction pool not ready for block production.")]
|
||||
TransactionPoolNotReady,
|
||||
#[display(fmt = "Database: {}", _0)]
|
||||
DatabaseError(sp_database::error::DatabaseError),
|
||||
#[error("Database")]
|
||||
DatabaseError(#[from] sp_database::error::DatabaseError),
|
||||
/// A convenience variant for String
|
||||
#[display(fmt = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Msg(String),
|
||||
}
|
||||
|
||||
impl error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||
match self {
|
||||
Error::Consensus(e) => Some(e),
|
||||
Error::Blockchain(e) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for Error {
|
||||
fn from(s: &'a str) -> Self {
|
||||
Error::Msg(s.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Error {
|
||||
fn from(s: String) -> Self {
|
||||
Error::Msg(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<dyn sp_state_machine::Error + Send + Sync>> for Error {
|
||||
fn from(e: Box<dyn sp_state_machine::Error + Send + Sync>) -> Self {
|
||||
Self::from_state(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<dyn sp_state_machine::Error>> for Error {
|
||||
fn from(e: Box<dyn sp_state_machine::Error>) -> Self {
|
||||
Self::from_state(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Chain a blockchain error.
|
||||
pub fn from_blockchain(e: Box<Error>) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user