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
@@ -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>(