Merge pull request #1116 from rphmeier/die_display
Have `die_with_error` use `fmt::Display` rather than Debug
This commit is contained in:
@@ -60,6 +60,28 @@ pub enum TransactionError {
|
||||
InvalidGasLimit(OutOfBounds<U256>),
|
||||
}
|
||||
|
||||
impl fmt::Display for TransactionError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::TransactionError::*;
|
||||
let msg = match *self {
|
||||
AlreadyImported => "Already imported".into(),
|
||||
Old => "No longer valid".into(),
|
||||
TooCheapToReplace => "Gas price too low to replace".into(),
|
||||
LimitReached => "Transaction limit reached".into(),
|
||||
InsufficientGasPrice { minimal, got } =>
|
||||
format!("Insufficient gas price. Min={}, Given={}", minimal, got),
|
||||
InsufficientBalance { balance, cost } =>
|
||||
format!("Insufficient balance for transaction. Balance={}, Cost={}",
|
||||
balance, cost),
|
||||
GasLimitExceeded { limit, got } =>
|
||||
format!("Gas limit exceeded. Limit={}, Given={}", limit, got),
|
||||
InvalidGasLimit(ref err) => format!("Invalid gas limit. {}", err),
|
||||
};
|
||||
|
||||
f.write_fmt(format_args!("Transaction error ({})", msg))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
/// Errors concerning block processing.
|
||||
pub enum BlockError {
|
||||
@@ -98,7 +120,7 @@ pub enum BlockError {
|
||||
MismatchedH256SealElement(Mismatch<H256>),
|
||||
/// Proof-of-work aspect of seal, which we assume is a 256-bit value, is invalid.
|
||||
InvalidProofOfWork(OutOfBounds<U256>),
|
||||
/// Some low-level aspect of the seal in incorrect.
|
||||
/// Some low-level aspect of the seal is incorrect.
|
||||
InvalidSeal,
|
||||
/// Gas limit header field is invalid.
|
||||
InvalidGasLimit(OutOfBounds<U256>),
|
||||
@@ -121,6 +143,43 @@ pub enum BlockError {
|
||||
UnknownUncleParent(H256),
|
||||
}
|
||||
|
||||
impl fmt::Display for BlockError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::BlockError::*;
|
||||
|
||||
let msg = match *self {
|
||||
TooManyUncles(ref oob) => format!("Block has too many uncles. {}", oob),
|
||||
ExtraDataOutOfBounds(ref oob) => format!("Extra block data too long. {}", oob),
|
||||
InvalidSealArity(ref mis) => format!("Block seal in incorrect format: {}", mis),
|
||||
TooMuchGasUsed(ref oob) => format!("Block has too much gas used. {}", oob),
|
||||
InvalidUnclesHash(ref mis) => format!("Block has invalid uncles hash: {}", mis),
|
||||
UncleTooOld(ref oob) => format!("Uncle block is too old. {}", oob),
|
||||
UncleIsBrother(ref oob) => format!("Uncle from same generation as block. {}", oob),
|
||||
UncleInChain(ref hash) => format!("Uncle {} already in chain", hash),
|
||||
UncleParentNotInChain(ref hash) => format!("Uncle {} has a parent not in the chain", hash),
|
||||
InvalidStateRoot(ref mis) => format!("Invalid state root in header: {}", mis),
|
||||
InvalidGasUsed(ref mis) => format!("Invalid gas used in header: {}", mis),
|
||||
InvalidTransactionsRoot(ref mis) => format!("Invalid transactions root in header: {}", mis),
|
||||
DifficultyOutOfBounds(ref oob) => format!("Invalid block difficulty: {}", oob),
|
||||
InvalidDifficulty(ref mis) => format!("Invalid block difficulty: {}", mis),
|
||||
MismatchedH256SealElement(ref mis) => format!("Seal element out of bounds: {}", mis),
|
||||
InvalidProofOfWork(ref oob) => format!("Block has invalid PoW: {}", oob),
|
||||
InvalidSeal => "Block has invalid seal.".into(),
|
||||
InvalidGasLimit(ref oob) => format!("Invalid gas limit: {}", oob),
|
||||
InvalidReceiptsRoot(ref mis) => format!("Invalid receipts trie root in header: {}", mis),
|
||||
InvalidTimestamp(ref oob) => format!("Invalid timestamp in header: {}", oob),
|
||||
InvalidLogBloom(ref oob) => format!("Invalid log bloom in header: {}", oob),
|
||||
InvalidParentHash(ref mis) => format!("Invalid parent hash: {}", mis),
|
||||
InvalidNumber(ref mis) => format!("Invalid number in header: {}", mis),
|
||||
RidiculousNumber(ref oob) => format!("Implausible block number. {}", oob),
|
||||
UnknownParent(ref hash) => format!("Unknown parent: {}", hash),
|
||||
UnknownUncleParent(ref hash) => format!("Unknown uncle parent: {}", hash),
|
||||
};
|
||||
|
||||
f.write_fmt(format_args!("Block error ({})", msg))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
/// Import to the block queue result
|
||||
pub enum ImportError {
|
||||
@@ -132,6 +191,18 @@ pub enum ImportError {
|
||||
KnownBad,
|
||||
}
|
||||
|
||||
impl fmt::Display for ImportError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let msg = match *self {
|
||||
ImportError::AlreadyInChain => "block already in chain",
|
||||
ImportError::AlreadyQueued => "block already in the block queue",
|
||||
ImportError::KnownBad => "block known to be bad",
|
||||
};
|
||||
|
||||
f.write_fmt(format_args!("Block import error ({})", msg))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// General error type which should be capable of representing all errors in ethcore.
|
||||
pub enum Error {
|
||||
@@ -155,6 +226,23 @@ pub enum Error {
|
||||
PowInvalid,
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Error::Client(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||
Error::Util(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||
Error::Block(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||
Error::Execution(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||
Error::Transaction(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||
Error::Import(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||
Error::UnknownEngineName(ref name) =>
|
||||
f.write_fmt(format_args!("Unknown engine name ({})", name)),
|
||||
Error::PowHashInvalid => f.write_str("Invalid or out of date PoW hash."),
|
||||
Error::PowInvalid => f.write_str("Invalid nonce or mishash"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Result of import block operation.
|
||||
pub type ImportResult = Result<H256, Error>;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ use util::Bytes;
|
||||
use trace::Trace;
|
||||
use types::log_entry::LogEntry;
|
||||
use ipc::binary::BinaryConvertError;
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
@@ -104,6 +105,28 @@ pub enum ExecutionError {
|
||||
TransactionMalformed(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for ExecutionError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::ExecutionError::*;
|
||||
|
||||
let msg = match *self {
|
||||
NotEnoughBaseGas { required, got } =>
|
||||
format!("Not enough base gas. {} is required, but only {} paid", required, got),
|
||||
BlockGasLimitReached { gas_limit, gas_used, gas } =>
|
||||
format!("Block gas limit reached. The limit is {}, {} has \
|
||||
already been used, and {} more is required", gas_limit, gas_used, gas),
|
||||
InvalidNonce { expected, got } =>
|
||||
format!("Invalid transaction nonce: expected {}, found {}", expected, got),
|
||||
NotEnoughCash { required, got } =>
|
||||
format!("Cost of transaction exceeds sender balance. {} is required \
|
||||
but the sender only has {}", required, got),
|
||||
Internal => "Internal evm error".into(),
|
||||
TransactionMalformed(ref err) => format!("Malformed transaction: {}", err),
|
||||
};
|
||||
|
||||
f.write_fmt(format_args!("Transaction execution error ({}).", msg))
|
||||
}
|
||||
}
|
||||
|
||||
/// Transaction execution result.
|
||||
pub type ExecutionResult = Result<Executed, ExecutionError>;
|
||||
|
||||
Reference in New Issue
Block a user