Skip to content

Commit 4cc0032

Browse files
levisyingzliudan
authored andcommitted
accounts/abi: context info on unpack-errors (ethereum#28529)
adds contextual information to errors returned by unpack
1 parent 7af72e6 commit 4cc0032

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

accounts/abi/error.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package abi
1818

1919
import (
2020
"bytes"
21-
"errors"
2221
"fmt"
2322
"strings"
2423

@@ -84,10 +83,10 @@ func (e Error) String() string {
8483

8584
func (e *Error) Unpack(data []byte) (interface{}, error) {
8685
if len(data) < 4 {
87-
return "", errors.New("invalid data for unpacking")
86+
return "", fmt.Errorf("insufficient data for unpacking: have %d, want at least 4", len(data))
8887
}
8988
if !bytes.Equal(data[:4], e.ID[:4]) {
90-
return "", errors.New("invalid data for unpacking")
89+
return "", fmt.Errorf("invalid identifier, have %#x want %#x", data[:4], e.ID[:4])
9190
}
9291
return e.Inputs.Unpack(data[4:])
9392
}

0 commit comments

Comments
 (0)