mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
chore: improve custom error formatting in revert messages
This commit is contained in:
parent
3ef918538e
commit
71f257457d
1 changed files with 13 additions and 1 deletions
|
|
@ -51,7 +51,7 @@ func newRevertError(revert []byte) *revertError {
|
||||||
if errUnpack == nil {
|
if errUnpack == nil {
|
||||||
err = fmt.Errorf("%w: %v", vm.ErrExecutionReverted, reason)
|
err = fmt.Errorf("%w: %v", vm.ErrExecutionReverted, reason)
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("%w: %v", vm.ErrExecutionReverted, hexutil.Encode(revert))
|
err = fmt.Errorf("%w: %v", vm.ErrExecutionReverted, formatRevertError(revert))
|
||||||
}
|
}
|
||||||
return &revertError{
|
return &revertError{
|
||||||
error: err,
|
error: err,
|
||||||
|
|
@ -59,6 +59,18 @@ func newRevertError(revert []byte) *revertError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// formatRevertError formats the revert data into a custom error message
|
||||||
|
func formatRevertError(revert []byte) string {
|
||||||
|
if len(revert) >= 4 {
|
||||||
|
selector := revert[:4]
|
||||||
|
params := revert[4:]
|
||||||
|
return fmt.Sprintf("custom error %s: %s",
|
||||||
|
hexutil.Encode(selector),
|
||||||
|
hexutil.Encode(params))
|
||||||
|
}
|
||||||
|
return hexutil.Encode(revert)
|
||||||
|
}
|
||||||
|
|
||||||
// TxIndexingError is an API error that indicates the transaction indexing is not
|
// TxIndexingError is an API error that indicates the transaction indexing is not
|
||||||
// fully finished yet with JSON error code and a binary data blob.
|
// fully finished yet with JSON error code and a binary data blob.
|
||||||
type TxIndexingError struct{}
|
type TxIndexingError struct{}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue