Properly handle execution reverts in eth_call JSON-RPC endpoint#297
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
| return nil, getErrorForCode(evmResult.ErrorCode) | ||
| if evmResult.ErrorCode == evmTypes.ExecutionErrCodeExecutionReverted { | ||
| return nil, errs.NewRevertError(evmResult.ReturnedData) | ||
| } else { |
| function assertError() public pure { | ||
| require(false, "Assert Error Message"); | ||
| } | ||
|
|
||
| function customError() public pure { | ||
| revert MyCustomError(5, "Value is too low"); | ||
| } |
| let block = await web3.eth.getBlock(latestHeight) | ||
| assert.equal(block.logsBloom, res.receipt.logsBloom) | ||
|
|
||
| // check that revert reason for custom error is correctly returned for signed transaction |
There was a problem hiding this comment.
Actionable comments posted: 0
Outside diff range and nitpick comments (2)
services/requester/requester.go (2)
Line range hint
563-563: RefactorsignAndSendto reduce complexity.The
signAndSendfunction is too long, which can make it difficult to maintain and understand. Consider breaking it down into smaller, more manageable functions. For example, the concurrent operations for fetching the latest block and signer info could be extracted into separate methods.
Line range hint
669-669: RefactorgetErrorForCodeto simplify.The
getErrorForCodefunction has too many statements, making it complex and hard to maintain. Consider using a map to associate error codes with their corresponding errors, which can simplify the function and improve readability.+ var errorCodeMap = map[evmTypes.ErrorCode]error{ + evmTypes.ValidationErrCodeGasUintOverflow: gethVM.ErrGasUintOverflow, + // Add other mappings here... + } + + func getErrorForCode(errorCode evmTypes.ErrorCode) error { + if err, ok := errorCodeMap[errorCode]; ok { + return err + } + return fmt.Errorf("unknown error code: %d", errorCode) + }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- services/requester/requester.go (1 hunks)
Additional context used
golangci-lint
services/requester/requester.go
563-563: Function 'signAndSend' is too long (82 > 60) (funlen)
669-669: Function 'getErrorForCode' has too many statements (66 > 40) (funlen)
Additional comments not posted (1)
services/requester/requester.go (1)
329-333: Properly handle execution reverts ineth_call.The updated error handling in the
Callmethod correctly checks for execution reverts and returns aRevertErrorwhen appropriate. This aligns with the PR's objective to enhance error parsing for better user feedback.
Closes: #296
Description
This can be used by other tools to correctly parse the revert reason to a human-friendly error message.
For contributor use:
masterbranchFiles changedin the Github PR explorerSummary by CodeRabbit
New Features
Bug Fixes
Tests
Chores