-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly handle execution reverts in eth_call
JSON-RPC endpoint
#297
Properly handle execution reverts in eth_call
JSON-RPC endpoint
#297
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
services/requester/requester.go
Outdated
return nil, getErrorForCode(evmResult.ErrorCode) | ||
if evmResult.ErrorCode == evmTypes.ExecutionErrCodeExecutionReverted { | ||
return nil, errs.NewRevertError(evmResult.ReturnedData) | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right 😅
Removed in 90d72ce
function assertError() public pure { | ||
require(false, "Assert Error Message"); | ||
} | ||
|
||
function customError() public pure { | ||
revert MyCustomError(5, "Value is too low"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
@@ -103,4 +103,74 @@ it('deploy contract and interact', async() => { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (2)
services/requester/requester.go (2)
Line range hint
563-563
: RefactorsignAndSend
to reduce complexity.The
signAndSend
function 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
: RefactorgetErrorForCode
to simplify.The
getErrorForCode
function 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
Call
method correctly checks for execution reverts and returns aRevertError
when 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:
master
branchFiles changed
in the Github PR explorerSummary by CodeRabbit
New Features
Bug Fixes
Tests
Chores