internal/ethapi: return revert reason for eth_call (#21083)
* internal/ethapi: return revert reason for eth_call * internal/ethapi: moved revert reason logic to doCall * accounts/abi/bind/backends: added revert reason logic to simulated backend * internal/ethapi: fixed linting error * internal/ethapi: check if require reason can be unpacked * internal/ethapi: better error logic * internal/ethapi: simplify logic * internal/ethapi: return vmError() * internal/ethapi: move handling of revert out of docall * graphql: removed revert logic until spec change * rpc: internal/ethapi: added custom error types * graphql: use returndata instead of return Return() checks if there is an error. If an error is found, we return nil. For most use cases it can be beneficial to return the output even if there was an error. This code should be changed anyway once the spec supports error reasons in graphql responses * accounts/abi/bind/backends: added tests for revert reason * internal/ethapi: add errorCode to revert error * internal/ethapi: add errorCode of 3 to revertError * internal/ethapi: unified estimateGasErrors, simplified logic * internal/ethapi: unified handling of errors in DoEstimateGas * rpc: print error data field * accounts/abi/bind/backends: unify simulatedBackend and RPC * internal/ethapi: added binary data to revertError data * internal/ethapi: refactored unpacking logic into newRevertError * accounts/abi/bind/backends: fix EstimateGas * accounts, console, internal, rpc: minor error interface cleanups * Revert "accounts, console, internal, rpc: minor error interface cleanups" This reverts commit2d3ef53c53
. * re-apply the good parts of2d3ef53c53
* rpc: add test for returning server error data from client Co-authored-by: rjl493456442 <garyrong0905@gmail.com> Co-authored-by: Péter Szilágyi <peterke@gmail.com> Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
committed by
GitHub
parent
88125d8bd0
commit
0b3f3be2b5
@ -413,9 +413,7 @@ func (b *bridge) Send(call jsre.Call) (goja.Value, error) {
|
||||
resp.Set("id", req.ID)
|
||||
|
||||
var result json.RawMessage
|
||||
err = b.client.Call(&result, req.Method, req.Params...)
|
||||
switch err := err.(type) {
|
||||
case nil:
|
||||
if err = b.client.Call(&result, req.Method, req.Params...); err == nil {
|
||||
if result == nil {
|
||||
// Special case null because it is decoded as an empty
|
||||
// raw message for some reason.
|
||||
@ -428,19 +426,24 @@ func (b *bridge) Send(call jsre.Call) (goja.Value, error) {
|
||||
}
|
||||
resultVal, err := parse(goja.Null(), call.VM.ToValue(string(result)))
|
||||
if err != nil {
|
||||
setError(resp, -32603, err.Error())
|
||||
setError(resp, -32603, err.Error(), nil)
|
||||
} else {
|
||||
resp.Set("result", resultVal)
|
||||
}
|
||||
}
|
||||
case rpc.Error:
|
||||
setError(resp, err.ErrorCode(), err.Error())
|
||||
default:
|
||||
setError(resp, -32603, err.Error())
|
||||
} else {
|
||||
code := -32603
|
||||
var data interface{}
|
||||
if err, ok := err.(rpc.Error); ok {
|
||||
code = err.ErrorCode()
|
||||
}
|
||||
if err, ok := err.(rpc.DataError); ok {
|
||||
data = err.ErrorData()
|
||||
}
|
||||
setError(resp, code, err.Error(), data)
|
||||
}
|
||||
resps = append(resps, resp)
|
||||
}
|
||||
|
||||
// Return the responses either to the callback (if supplied)
|
||||
// or directly as the return value.
|
||||
var result goja.Value
|
||||
@ -456,8 +459,14 @@ func (b *bridge) Send(call jsre.Call) (goja.Value, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func setError(resp *goja.Object, code int, msg string) {
|
||||
resp.Set("error", map[string]interface{}{"code": code, "message": msg})
|
||||
func setError(resp *goja.Object, code int, msg string, data interface{}) {
|
||||
err := make(map[string]interface{})
|
||||
err["code"] = code
|
||||
err["message"] = msg
|
||||
if data != nil {
|
||||
err["data"] = data
|
||||
}
|
||||
resp.Set("error", err)
|
||||
}
|
||||
|
||||
// isNumber returns true if input value is a JS number.
|
||||
|
Reference in New Issue
Block a user