-
Notifications
You must be signed in to change notification settings - Fork 20.5k
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
internal/ethapi: expose raw error data #30659
Conversation
@fjl @MariusVanDerWijden Please take a look |
Please check PR #30653 first |
WDYT about this? @rjl493456442 @Confucian-e diff --git a/internal/ethapi/errors.go b/internal/ethapi/errors.go
index ae38061234..272d427c1f 100644
--- a/internal/ethapi/errors.go
+++ b/internal/ethapi/errors.go
@@ -29,10 +29,16 @@ import (
// revertError is an API error that encompasses an EVM revert with JSON error
// code and a binary data blob.
type revertError struct {
- error
reason string // revert reason hex encoded
}
+func (e *revertError) Error() string {
+ if e.reason != "" {
+ return fmt.Sprintf("%s: %v", vm.ErrExecutionReverted, e.reason)
+ }
+ return vm.ErrExecutionReverted.Error()
+}
+
// ErrorCode returns the JSON error code for a revert.
// See: https://github.com/ethereum/wiki/wiki/JSON-RPC-Error-Codes-Improvement-Proposal
func (e *revertError) ErrorCode() int {
@@ -46,15 +52,12 @@ func (e *revertError) ErrorData() interface{} {
// newRevertError creates a revertError instance with the provided revert data.
func newRevertError(revert []byte) *revertError {
- err := vm.ErrExecutionReverted
-
- reason, errUnpack := abi.UnpackRevert(revert)
- if errUnpack == nil {
- err = fmt.Errorf("%w: %v", vm.ErrExecutionReverted, reason)
+ reason := hexutil.Encode(revert)
+ if r, errUnpack := abi.UnpackRevert(revert); errUnpack == nil {
+ reason = r
}
return &revertError{
- error: err,
- reason: hexutil.Encode(revert),
+ reason: reason,
}
} |
@MariusVanDerWijden sgtm and feel free to push the changes! |
Maybe you could read this: #30653 (comment) |
@Confucian-e I do see the point you raised. However, I think we have to wait until the community gradually upgrade their infra to new version. |
Okay, I respect your opinion. |
I think we should not expose the revert data in error messages. Doing so will only increase the incentive to resort to error message parsing. You can see what will happen down that path in the example of this spec issue: ethereum/execution-apis#463 Since the revert reason is returned by Geth with a dedicated error code, we should just provide a better way of extracting it on the client side. Here is a PR to do that: #30669 |
Alternative approach for #30653