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:
Bernhard Schuster
2020-10-28 15:04:56 +01:00
committed by GitHub
parent 1679919830
commit 9687759774
17 changed files with 152 additions and 128 deletions
@@ -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)
}
}