Move ethcore::Error to error_chain (#8386)

* WIP

* Convert Ethcore error to use error_chain

* Use error_chain for ImportError and BlockImportError

* Fix error pattern matches for error_chain in miner

* Implement explicit From for AccountsError

* Fix pattern matches for ErrorKinds

* Handle ethcore error_chain in light client

* Explicitly define Result type to avoid shadowing

* Fix remaining Error pattern matches

* Fix tab space formatting

* Helps if the tests compile

* Fix error chain matching after merge
This commit is contained in:
Andrew Jones
2018-04-19 10:52:54 +01:00
committed by Afri Schoedon
parent 2257bc8e2f
commit 14361cc7b1
27 changed files with 249 additions and 274 deletions

View File

@@ -19,7 +19,7 @@
use std::fmt;
use ethcore::account_provider::{SignError as AccountError};
use ethcore::error::{Error as EthcoreError, CallError};
use ethcore::error::{Error as EthcoreError, ErrorKind, CallError};
use jsonrpc_core::{futures, Error, ErrorCode, Value};
use rlp::DecoderError;
use transaction::Error as TransactionError;
@@ -306,10 +306,10 @@ pub fn private_message_block_id_not_supported() -> Error {
}
}
pub fn transaction_message(error: TransactionError) -> String {
pub fn transaction_message(error: &TransactionError) -> String {
use self::TransactionError::*;
match error {
match *error {
AlreadyImported => "Transaction with the same hash was already imported.".into(),
Old => "Transaction nonce is too low. Try incrementing the nonce.".into(),
TooCheapToReplace => {
@@ -330,7 +330,7 @@ pub fn transaction_message(error: TransactionError) -> String {
GasLimitExceeded { limit, got } => {
format!("Transaction cost exceeds current gas limit. Limit: {}, got: {}. Try decreasing supplied gas.", limit, got)
},
InvalidSignature(sig) => format!("Invalid signature: {}", sig),
InvalidSignature(ref sig) => format!("Invalid signature: {}", sig),
InvalidChainId => "Invalid chain id.".into(),
InvalidGasLimit(_) => "Supplied gas is beyond limit.".into(),
SenderBanned => "Sender is banned in local queue.".into(),
@@ -342,7 +342,7 @@ pub fn transaction_message(error: TransactionError) -> String {
pub fn transaction<T: Into<EthcoreError>>(error: T) -> Error {
let error = error.into();
if let EthcoreError::Transaction(e) = error {
if let ErrorKind::Transaction(ref e) = *error.kind() {
Error {
code: ErrorCode::ServerError(codes::TRANSACTION_ERROR),
message: transaction_message(e),