Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Return errors from eth_call RPC (#2498)
Browse files Browse the repository at this point in the history
* propagate call errors

* add error code for execution error
  • Loading branch information
keorn authored and gavofyork committed Oct 9, 2016
1 parent d6cad29 commit 271bcf4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
19 changes: 17 additions & 2 deletions rpc/src/v1/helpers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ macro_rules! rpc_unimplemented {
}

use std::fmt;
use ethcore::error::Error as EthcoreError;
use ethcore::error::{Error as EthcoreError, CallError};
use ethcore::account_provider::{Error as AccountError};
use fetch::FetchError;
use jsonrpc_core::{Error, ErrorCode, Value};
Expand All @@ -34,6 +34,7 @@ mod codes {
pub const NO_NEW_WORK: i64 = -32003;
pub const UNKNOWN_ERROR: i64 = -32009;
pub const TRANSACTION_ERROR: i64 = -32010;
pub const EXECUTION_ERROR: i64 = -32015;
pub const ACCOUNT_LOCKED: i64 = -32020;
pub const PASSWORD_INVALID: i64 = -32021;
pub const ACCOUNT_ERROR: i64 = -32023;
Expand Down Expand Up @@ -109,6 +110,14 @@ pub fn invalid_params<T: fmt::Debug>(param: &str, details: T) -> Error {
}
}

pub fn execution<T: fmt::Debug>(data: T) -> Error {
Error {
code: ErrorCode::ServerError(codes::EXECUTION_ERROR),
message: "Transaction execution error.".into(),
data: Some(Value::String(format!("{:?}", data))),
}
}

pub fn state_pruned() -> Error {
Error {
code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST),
Expand Down Expand Up @@ -219,4 +228,10 @@ pub fn from_transaction_error(error: EthcoreError) -> Error {
}
}


pub fn from_call_error(error: CallError) -> Error {
match error {
CallError::StatePruned => state_pruned(),
CallError::Execution(e) => execution(e),
CallError::TransactionNotFound => internal("{}, this should not be the case with eth_call, most likely a bug.", CallError::TransactionNotFound),
}
}
5 changes: 4 additions & 1 deletion rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,10 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
num => take_weak!(self.client).call(&signed, num.into(), Default::default()),
};

Ok(r.map(|e| Bytes(e.output)).unwrap_or(Bytes::new(vec![])))
match r {
Ok(b) => Ok(Bytes(b.output)),
Err(e) => Err(errors::from_call_error(e)),
}
}

fn estimate_gas(&self, request: CallRequest, num: Trailing<BlockNumber>) -> Result<RpcU256, Error> {
Expand Down

0 comments on commit 271bcf4

Please sign in to comment.