aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/hexutil/hexutil.go6
-rw-r--r--common/hexutil/hexutil_test.go9
2 files changed, 9 insertions, 6 deletions
diff --git a/common/hexutil/hexutil.go b/common/hexutil/hexutil.go
index 16863f6c0..b66c0d3fe 100644
--- a/common/hexutil/hexutil.go
+++ b/common/hexutil/hexutil.go
@@ -60,7 +60,11 @@ func Decode(input string) ([]byte, error) {
if !has0xPrefix(input) {
return nil, ErrMissingPrefix
}
- return hex.DecodeString(input[2:])
+ b, err := hex.DecodeString(input[2:])
+ if err != nil {
+ err = mapError(err)
+ }
+ return b, err
}
// MustDecode decodes a hex string with 0x prefix. It panics for invalid input.
diff --git a/common/hexutil/hexutil_test.go b/common/hexutil/hexutil_test.go
index 68d8a40e0..d18f08833 100644
--- a/common/hexutil/hexutil_test.go
+++ b/common/hexutil/hexutil_test.go
@@ -18,7 +18,6 @@ package hexutil
import (
"bytes"
- "encoding/hex"
"math/big"
"testing"
)
@@ -60,10 +59,10 @@ var (
// invalid
{input: ``, wantErr: ErrEmptyString},
{input: `0`, wantErr: ErrMissingPrefix},
- {input: `0x0`, wantErr: hex.ErrLength},
- {input: `0x023`, wantErr: hex.ErrLength},
- {input: `0xxx`, wantErr: hex.InvalidByteError('x')},
- {input: `0x01zz01`, wantErr: hex.InvalidByteError('z')},
+ {input: `0x0`, wantErr: ErrOddLength},
+ {input: `0x023`, wantErr: ErrOddLength},
+ {input: `0xxx`, wantErr: ErrSyntax},
+ {input: `0x01zz01`, wantErr: ErrSyntax},
// valid
{input: `0x`, want: []byte{}},
{input: `0X`, want: []byte{}},