mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 08:18:04 +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
Generated
+5
-3
@@ -8086,7 +8086,6 @@ dependencies = [
|
||||
name = "sp-blockchain"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"derive_more",
|
||||
"log",
|
||||
"lru 0.4.3",
|
||||
"parity-scale-codec",
|
||||
@@ -8096,6 +8095,7 @@ dependencies = [
|
||||
"sp-database",
|
||||
"sp-runtime",
|
||||
"sp-state-machine",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -8110,7 +8110,6 @@ dependencies = [
|
||||
name = "sp-consensus"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"derive_more",
|
||||
"futures 0.3.5",
|
||||
"futures-timer 3.0.2",
|
||||
"libp2p",
|
||||
@@ -8129,6 +8128,7 @@ dependencies = [
|
||||
"sp-utils",
|
||||
"sp-version",
|
||||
"substrate-prometheus-endpoint",
|
||||
"thiserror",
|
||||
"wasm-timer",
|
||||
]
|
||||
|
||||
@@ -8235,6 +8235,7 @@ dependencies = [
|
||||
"sp-std",
|
||||
"sp-storage",
|
||||
"substrate-bip39",
|
||||
"thiserror",
|
||||
"tiny-bip39",
|
||||
"tiny-keccak",
|
||||
"twox-hash",
|
||||
@@ -8289,11 +8290,11 @@ dependencies = [
|
||||
name = "sp-inherents"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"derive_more",
|
||||
"parity-scale-codec",
|
||||
"parking_lot 0.10.2",
|
||||
"sp-core",
|
||||
"sp-std",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -8564,6 +8565,7 @@ dependencies = [
|
||||
"sp-runtime",
|
||||
"sp-std",
|
||||
"sp-trie",
|
||||
"thiserror",
|
||||
"trie-db",
|
||||
"trie-root",
|
||||
]
|
||||
|
||||
@@ -114,8 +114,7 @@ pub trait CallExecutor<B: BlockT> {
|
||||
) -> Result<(Vec<u8>, StorageProof), sp_blockchain::Error> {
|
||||
let trie_state = state.as_trie_backend()
|
||||
.ok_or_else(||
|
||||
Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof)
|
||||
as Box<dyn sp_state_machine::Error>
|
||||
sp_blockchain::Error::from_state(Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof) as Box<_>)
|
||||
)?;
|
||||
self.prove_at_trie_state(trie_state, overlay, method, call_data)
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ pub fn build_proof<Header, Hasher, BlocksI, HashesI>(
|
||||
prove_read_on_trie_backend(
|
||||
trie_storage,
|
||||
blocks.into_iter().map(|number| encode_cht_key(number)),
|
||||
).map_err(ClientError::Execution)
|
||||
).map_err(ClientError::from_state)
|
||||
}
|
||||
|
||||
/// Check CHT-based header proof.
|
||||
@@ -150,7 +150,7 @@ pub fn check_proof<Header, Hasher>(
|
||||
.map(|mut map| map
|
||||
.remove(local_cht_key)
|
||||
.expect("checked proof of local_cht_key; qed"))
|
||||
.map_err(|e| ClientError::from(e)),
|
||||
.map_err(ClientError::from_state),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ pub fn check_proof_on_proving_backend<Header, Hasher>(
|
||||
read_proof_check_on_proving_backend::<Hasher>(
|
||||
proving_backend,
|
||||
local_cht_key,
|
||||
).map_err(|e| ClientError::from(e)),
|
||||
).map_err(ClientError::from_state),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ readme = "README.md"
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.8"
|
||||
log = "0.4.11"
|
||||
lru = "0.4.0"
|
||||
parking_lot = "0.10.0"
|
||||
derive_more = "0.99.2"
|
||||
thiserror = "1.0.21"
|
||||
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive"] }
|
||||
sp-consensus = { version = "0.8.0", path = "../consensus/common" }
|
||||
sp-runtime = { version = "2.0.0", path = "../runtime" }
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
derive_more = "0.99.2"
|
||||
thiserror = "1.0.21"
|
||||
libp2p = { version = "0.28.1", default-features = false }
|
||||
log = "0.4.8"
|
||||
sp-core = { path= "../../core", version = "2.0.0"}
|
||||
|
||||
@@ -24,73 +24,73 @@ use std::error;
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// Error type.
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// Missing state at block with given descriptor.
|
||||
#[display(fmt="State unavailable at block {}", _0)]
|
||||
#[error("State unavailable at block {0}")]
|
||||
StateUnavailable(String),
|
||||
/// I/O terminated unexpectedly
|
||||
#[display(fmt="I/O terminated unexpectedly.")]
|
||||
#[error("I/O terminated unexpectedly.")]
|
||||
IoTerminated,
|
||||
/// Intermediate missing.
|
||||
#[display(fmt="Missing intermediate.")]
|
||||
#[error("Missing intermediate.")]
|
||||
NoIntermediate,
|
||||
/// Intermediate is of wrong type.
|
||||
#[display(fmt="Invalid intermediate.")]
|
||||
#[error("Invalid intermediate.")]
|
||||
InvalidIntermediate,
|
||||
/// Unable to schedule wake-up.
|
||||
#[display(fmt="Timer error: {}", _0)]
|
||||
FaultyTimer(std::io::Error),
|
||||
#[error("Timer error: {0}")]
|
||||
FaultyTimer(#[from] std::io::Error),
|
||||
/// Error while working with inherent data.
|
||||
#[display(fmt="InherentData error: {}", _0)]
|
||||
InherentData(sp_inherents::Error),
|
||||
#[error("InherentData error: {0}")]
|
||||
InherentData(#[from] sp_inherents::Error),
|
||||
/// Unable to propose a block.
|
||||
#[display(fmt="Unable to create block proposal.")]
|
||||
#[error("Unable to create block proposal.")]
|
||||
CannotPropose,
|
||||
/// Error checking signature
|
||||
#[display(fmt="Message signature {:?} by {:?} is invalid.", _0, _1)]
|
||||
#[error("Message signature {0:?} by {1:?} is invalid.")]
|
||||
InvalidSignature(Vec<u8>, Vec<u8>),
|
||||
/// 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,
|
||||
/// Account is not an authority.
|
||||
#[display(fmt="Message sender {:?} is not a valid authority.", _0)]
|
||||
#[error("Message sender {0:?} is not a valid authority")]
|
||||
InvalidAuthority(Public),
|
||||
/// Authoring interface does not match the runtime.
|
||||
#[display(fmt="Authoring for current \
|
||||
runtime is not supported. Native ({}) cannot author for on-chain ({}).", native, on_chain)]
|
||||
#[error("Authoring for current \
|
||||
runtime is not supported. Native ({native}) cannot author for on-chain ({on_chain}).")]
|
||||
IncompatibleAuthoringRuntime { native: RuntimeVersion, on_chain: RuntimeVersion },
|
||||
/// Authoring interface does not match the runtime.
|
||||
#[display(fmt="Authoring for current runtime is not supported since it has no version.")]
|
||||
#[error("Authoring for current runtime is not supported since it has no version.")]
|
||||
RuntimeVersionMissing,
|
||||
/// Authoring interface does not match the runtime.
|
||||
#[display(fmt="Authoring in current build is not supported since it has no runtime.")]
|
||||
#[error("Authoring in current build is not supported since it has no runtime.")]
|
||||
NativeRuntimeMissing,
|
||||
/// Justification requirements not met.
|
||||
#[display(fmt="Invalid justification.")]
|
||||
#[error("Invalid justification.")]
|
||||
InvalidJustification,
|
||||
/// Some other error.
|
||||
#[display(fmt="Other error: {}", _0)]
|
||||
Other(Box<dyn error::Error + Send>),
|
||||
#[error(transparent)]
|
||||
Other(#[from] Box<dyn error::Error + Sync + Send + 'static>),
|
||||
/// Error from the client while importing
|
||||
#[display(fmt="Import failed: {}", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Import failed: {0}")]
|
||||
ClientImport(String),
|
||||
/// Error from the client while importing
|
||||
#[display(fmt="Chain lookup failed: {}", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Chain lookup failed: {0}")]
|
||||
ChainLookup(String),
|
||||
/// Signing failed
|
||||
#[display(fmt="Failed to sign using key: {:?}. Reason: {}", _0, _1)]
|
||||
#[error("Failed to sign using key: {0:?}. Reason: {1}")]
|
||||
CannotSign(Vec<u8>, String)
|
||||
}
|
||||
|
||||
impl error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||
match self {
|
||||
Error::FaultyTimer(ref err) => Some(err),
|
||||
Error::Other(ref err) => Some(&**err),
|
||||
_ => None,
|
||||
}
|
||||
impl core::convert::From<Public> for Error {
|
||||
fn from(p: Public) -> Self {
|
||||
Self::InvalidAuthority(p)
|
||||
}
|
||||
}
|
||||
|
||||
impl core::convert::From<String> for Error {
|
||||
fn from(s: String) -> Self {
|
||||
Self::StateUnavailable(s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,27 +30,25 @@ type BlockNumber = Option<u128>;
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// Error type.
|
||||
#[derive(Debug, derive_more::Display)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// Proposal provided not a block.
|
||||
#[display(fmt="Proposal provided not a block: decoding error: {}", _0)]
|
||||
BadProposalFormat(codec::Error),
|
||||
#[error("Proposal provided not a block: decoding error: {0}")]
|
||||
BadProposalFormat(#[from] codec::Error),
|
||||
/// Proposal had wrong parent hash.
|
||||
#[display(fmt="Proposal had wrong parent hash. Expected {:?}, got {:?}", expected, got)]
|
||||
#[error("Proposal had wrong parent hash. Expected {expected:?}, got {got:?}")]
|
||||
WrongParentHash { expected: String, got: String },
|
||||
/// Proposal had wrong number.
|
||||
#[display(fmt="Proposal had wrong number. Expected {:?}, got {:?}", expected, got)]
|
||||
#[error("Proposal had wrong number. Expected {expected:?}, got {got:?}")]
|
||||
WrongNumber { expected: BlockNumber, got: BlockNumber },
|
||||
/// Proposal exceeded the maximum size.
|
||||
#[display(
|
||||
fmt="Proposal exceeded the maximum size of {} by {} bytes.",
|
||||
"MAX_BLOCK_SIZE", "_0.saturating_sub(MAX_BLOCK_SIZE)"
|
||||
#[error(
|
||||
"Proposal exceeded the maximum size of {} by {} bytes.",
|
||||
MAX_BLOCK_SIZE, .0.saturating_sub(MAX_BLOCK_SIZE)
|
||||
)]
|
||||
ProposalTooLarge(usize),
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
/// Attempt to evaluate a substrate block as a node block, returning error
|
||||
/// upon any initial validity checks failing.
|
||||
pub fn evaluate_initial<Block: BlockT>(
|
||||
|
||||
@@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
[dependencies]
|
||||
sp-std = { version = "2.0.0", default-features = false, path = "../std" }
|
||||
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive"] }
|
||||
log = { version = "0.4.8", default-features = false }
|
||||
log = { version = "0.4.11", default-features = false }
|
||||
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
byteorder = { version = "1.3.2", default-features = false }
|
||||
primitive-types = { version = "0.7.0", default-features = false, features = ["codec"] }
|
||||
@@ -39,6 +39,7 @@ sp-storage = { version = "2.0.0", default-features = false, path = "../storage"
|
||||
parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] }
|
||||
futures = { version = "0.3.1", optional = true }
|
||||
dyn-clonable = { version = "0.9.0", optional = true }
|
||||
thiserror = { version = "1.0.21", optional = true }
|
||||
|
||||
# full crypto
|
||||
ed25519-dalek = { version = "1.0.0-pre.4", default-features = false, features = ["u64_backend", "alloc"], optional = true }
|
||||
@@ -74,6 +75,7 @@ default = ["std"]
|
||||
std = [
|
||||
"full_crypto",
|
||||
"log/std",
|
||||
"thiserror",
|
||||
"wasmi",
|
||||
"lazy_static",
|
||||
"parking_lot",
|
||||
|
||||
@@ -335,15 +335,19 @@ pub struct LocalizedSignature {
|
||||
|
||||
/// An error type for SS58 decoding.
|
||||
#[cfg(feature = "std")]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Debug, thiserror::Error)]
|
||||
pub enum PublicError {
|
||||
/// Bad alphabet.
|
||||
#[error("Base 58 requirement is violated")]
|
||||
BadBase58,
|
||||
/// Bad length.
|
||||
#[error("Length is bad")]
|
||||
BadLength,
|
||||
/// Unknown version.
|
||||
#[error("Unknown version")]
|
||||
UnknownVersion,
|
||||
/// Invalid checksum.
|
||||
#[error("Invalid checksum")]
|
||||
InvalidChecksum,
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ pub use sp_externalities::{Externalities, ExternalitiesExt};
|
||||
/// Code execution engine.
|
||||
pub trait CodeExecutor: Sized + Send + Sync + CallInWasm + Clone + 'static {
|
||||
/// Externalities error type.
|
||||
type Error: Display + Debug + Send + 'static;
|
||||
type Error: Display + Debug + Send + Sync + 'static;
|
||||
|
||||
/// Call a given method in the runtime. Returns a tuple of the result (either the output data
|
||||
/// or an execution error) together with a `bool`, which is true if native execution was used.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
/// The error type for database operations.
|
||||
#[derive(Debug)]
|
||||
pub struct DatabaseError(pub Box<dyn std::error::Error + Send>);
|
||||
pub struct DatabaseError(pub Box<dyn std::error::Error + Send + Sync + 'static>);
|
||||
|
||||
impl std::fmt::Display for DatabaseError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
|
||||
@@ -19,7 +19,7 @@ parking_lot = { version = "0.10.0", optional = true }
|
||||
sp-std = { version = "2.0.0", default-features = false, path = "../std" }
|
||||
sp-core = { version = "2.0.0", default-features = false, path = "../core" }
|
||||
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive"] }
|
||||
derive_more = { version = "0.99.2", optional = true }
|
||||
thiserror = { version = "1.0.21", optional = true }
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
@@ -28,5 +28,5 @@ std = [
|
||||
"sp-std/std",
|
||||
"codec/std",
|
||||
"sp-core/std",
|
||||
"derive_more",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
@@ -46,7 +46,8 @@ use std::{sync::Arc, format};
|
||||
|
||||
/// An error that can occur within the inherent data system.
|
||||
#[cfg(feature = "std")]
|
||||
#[derive(Debug, Encode, Decode, derive_more::Display)]
|
||||
#[derive(Debug, Encode, Decode, thiserror::Error)]
|
||||
#[error("Inherents: {0}")]
|
||||
pub struct Error(String);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
|
||||
@@ -184,6 +184,21 @@ impl From<UnknownTransaction> for TransactionValidityError {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::error::Error for TransactionValidityError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::fmt::Display for TransactionValidityError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let s: &'static str = (*self).into();
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
}
|
||||
|
||||
/// Information on a transaction's validity and, if valid, on how it relates to other transactions.
|
||||
pub type TransactionValidity = Result<ValidTransaction, TransactionValidityError>;
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ readme = "README.md"
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
log = { version = "0.4.8", optional = true }
|
||||
log = { version = "0.4.11", optional = true }
|
||||
thiserror = { version = "1.0.21", optional = true }
|
||||
parking_lot = { version = "0.10.0", optional = true }
|
||||
hash-db = { version = "0.15.2", default-features = false }
|
||||
trie-db = { version = "0.22.0", default-features = false }
|
||||
@@ -40,14 +41,15 @@ std = [
|
||||
"codec/std",
|
||||
"hash-db/std",
|
||||
"num-traits/std",
|
||||
"sp-core/std",
|
||||
"sp-externalities/std",
|
||||
"sp-std/std",
|
||||
"sp-core/std",
|
||||
"sp-externalities/std",
|
||||
"sp-std/std",
|
||||
"sp-trie/std",
|
||||
"trie-db/std",
|
||||
"trie-root/std",
|
||||
"log",
|
||||
"thiserror",
|
||||
"parking_lot",
|
||||
"rand",
|
||||
"sp-panic-handler",
|
||||
"sp-panic-handler",
|
||||
]
|
||||
|
||||
@@ -22,9 +22,9 @@ use sp_std::fmt;
|
||||
/// State Machine Error bound.
|
||||
///
|
||||
/// This should reflect Wasm error type bound for future compatibility.
|
||||
pub trait Error: 'static + fmt::Debug + fmt::Display + Send {}
|
||||
pub trait Error: 'static + fmt::Debug + fmt::Display + Send + Sync {}
|
||||
|
||||
impl<T: 'static + fmt::Debug + fmt::Display + Send> Error for T {}
|
||||
impl<T: 'static + fmt::Debug + fmt::Display + Send + Sync> Error for T {}
|
||||
|
||||
/// Externalities Error.
|
||||
///
|
||||
@@ -32,17 +32,18 @@ impl<T: 'static + fmt::Debug + fmt::Display + Send> Error for T {}
|
||||
/// would not be executed unless externalities were available. This is included for completeness,
|
||||
/// and as a transition away from the pre-existing framework.
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "std", derive(thiserror::Error))]
|
||||
pub enum ExecutionError {
|
||||
/// Backend error.
|
||||
#[cfg_attr(feature = "std", error("Backend error {0:?}"))]
|
||||
Backend(crate::DefaultError),
|
||||
/// The entry `:code` doesn't exist in storage so there's no way we can execute anything.
|
||||
#[cfg_attr(feature = "std", error("`:code` entry does not exist in storage"))]
|
||||
CodeEntryDoesNotExist,
|
||||
/// Backend is incompatible with execution proof generation process.
|
||||
#[cfg_attr(feature = "std", error("Unable to generate proof"))]
|
||||
UnableToGenerateProof,
|
||||
/// Invalid execution proof.
|
||||
#[cfg_attr(feature = "std", error("Invalid execution proof"))]
|
||||
InvalidProof,
|
||||
}
|
||||
|
||||
impl fmt::Display for ExecutionError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Externalities Error") }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user