diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index c026060ec1..1841c01faf 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -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", ] diff --git a/substrate/client/api/src/call_executor.rs b/substrate/client/api/src/call_executor.rs index d9d43900df..86e3440f19 100644 --- a/substrate/client/api/src/call_executor.rs +++ b/substrate/client/api/src/call_executor.rs @@ -114,8 +114,7 @@ pub trait CallExecutor { ) -> Result<(Vec, StorageProof), sp_blockchain::Error> { let trie_state = state.as_trie_backend() .ok_or_else(|| - Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof) - as Box + 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) } diff --git a/substrate/client/api/src/cht.rs b/substrate/client/api/src/cht.rs index 30cfd3a1b6..7fd7aa0dbc 100644 --- a/substrate/client/api/src/cht.rs +++ b/substrate/client/api/src/cht.rs @@ -122,7 +122,7 @@ pub fn build_proof( 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( .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( read_proof_check_on_proving_backend::( proving_backend, local_cht_key, - ).map_err(|e| ClientError::from(e)), + ).map_err(ClientError::from_state), ) } diff --git a/substrate/primitives/blockchain/Cargo.toml b/substrate/primitives/blockchain/Cargo.toml index 79c0b56616..f714aaaa1d 100644 --- a/substrate/primitives/blockchain/Cargo.toml +++ b/substrate/primitives/blockchain/Cargo.toml @@ -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" } diff --git a/substrate/primitives/blockchain/src/error.rs b/substrate/primitives/blockchain/src/error.rs index bc412e8358..6c9ab88fd1 100644 --- a/substrate/primitives/blockchain/src/error.rs +++ b/substrate/primitives/blockchain/src/error.rs @@ -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 = result::Result; /// 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), /// Blockchain error. - #[display(fmt = "Blockchain: {}", _0)] - Blockchain(Box), + #[error("Blockchain")] + Blockchain(#[source] Box), /// 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 for Error { + fn from(s: String) -> Self { + Error::Msg(s) + } +} + +impl From> for Error { + fn from(e: Box) -> Self { + Self::from_state(e) + } +} + +impl From> for Error { + fn from(e: Box) -> Self { + Self::from_state(e) + } +} + impl Error { /// Chain a blockchain error. pub fn from_blockchain(e: Box) -> Self { diff --git a/substrate/primitives/consensus/common/Cargo.toml b/substrate/primitives/consensus/common/Cargo.toml index e8eaa06ee0..9ce5460d8d 100644 --- a/substrate/primitives/consensus/common/Cargo.toml +++ b/substrate/primitives/consensus/common/Cargo.toml @@ -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"} diff --git a/substrate/primitives/consensus/common/src/error.rs b/substrate/primitives/consensus/common/src/error.rs index 0da7495890..a21bcf6cca 100644 --- a/substrate/primitives/consensus/common/src/error.rs +++ b/substrate/primitives/consensus/common/src/error.rs @@ -24,73 +24,73 @@ use std::error; pub type Result = std::result::Result; /// 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, Vec), /// 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), + #[error(transparent)] + Other(#[from] Box), /// 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, 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 for Error { + fn from(p: Public) -> Self { + Self::InvalidAuthority(p) + } +} + +impl core::convert::From for Error { + fn from(s: String) -> Self { + Self::StateUnavailable(s) } } diff --git a/substrate/primitives/consensus/common/src/evaluation.rs b/substrate/primitives/consensus/common/src/evaluation.rs index 76fcd5310b..edb148cdaa 100644 --- a/substrate/primitives/consensus/common/src/evaluation.rs +++ b/substrate/primitives/consensus/common/src/evaluation.rs @@ -30,27 +30,25 @@ type BlockNumber = Option; pub type Result = std::result::Result; /// 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( diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index 8b71bd7bbb..a97b8af156 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -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", diff --git a/substrate/primitives/core/src/ed25519.rs b/substrate/primitives/core/src/ed25519.rs index fcc84c5c2e..ad08f9ab8b 100644 --- a/substrate/primitives/core/src/ed25519.rs +++ b/substrate/primitives/core/src/ed25519.rs @@ -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, } diff --git a/substrate/primitives/core/src/traits.rs b/substrate/primitives/core/src/traits.rs index 406dba5338..97100ea58f 100644 --- a/substrate/primitives/core/src/traits.rs +++ b/substrate/primitives/core/src/traits.rs @@ -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. diff --git a/substrate/primitives/database/src/error.rs b/substrate/primitives/database/src/error.rs index 2e5d4557a9..3253839bbe 100644 --- a/substrate/primitives/database/src/error.rs +++ b/substrate/primitives/database/src/error.rs @@ -17,7 +17,7 @@ /// The error type for database operations. #[derive(Debug)] -pub struct DatabaseError(pub Box); +pub struct DatabaseError(pub Box); impl std::fmt::Display for DatabaseError { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { diff --git a/substrate/primitives/inherents/Cargo.toml b/substrate/primitives/inherents/Cargo.toml index 10c66b73ae..fdece1f9d3 100644 --- a/substrate/primitives/inherents/Cargo.toml +++ b/substrate/primitives/inherents/Cargo.toml @@ -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", ] diff --git a/substrate/primitives/inherents/src/lib.rs b/substrate/primitives/inherents/src/lib.rs index 9894296953..e91fb06e3f 100644 --- a/substrate/primitives/inherents/src/lib.rs +++ b/substrate/primitives/inherents/src/lib.rs @@ -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")] diff --git a/substrate/primitives/runtime/src/transaction_validity.rs b/substrate/primitives/runtime/src/transaction_validity.rs index e9e2f2b3d3..2191e59b9b 100644 --- a/substrate/primitives/runtime/src/transaction_validity.rs +++ b/substrate/primitives/runtime/src/transaction_validity.rs @@ -184,6 +184,21 @@ impl From 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; diff --git a/substrate/primitives/state-machine/Cargo.toml b/substrate/primitives/state-machine/Cargo.toml index 8940488319..95751bd4cb 100644 --- a/substrate/primitives/state-machine/Cargo.toml +++ b/substrate/primitives/state-machine/Cargo.toml @@ -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", ] diff --git a/substrate/primitives/state-machine/src/error.rs b/substrate/primitives/state-machine/src/error.rs index 489f6e6666..0b02c68f79 100644 --- a/substrate/primitives/state-machine/src/error.rs +++ b/substrate/primitives/state-machine/src/error.rs @@ -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 Error for T {} +impl Error for T {} /// Externalities Error. /// @@ -32,17 +32,18 @@ impl 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") } -}