aboutsummaryrefslogtreecommitdiffstats
path: root/common/hexutil/hexutil.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-06-27 20:02:43 +0800
committerGitHub <noreply@github.com>2017-06-27 20:02:43 +0800
commitbb366271fe33cf87b462dc5a25ac6c448ac6d2e1 (patch)
tree0a7b3e9e367c071a883068dc3452f259f65a1f67 /common/hexutil/hexutil.go
parent5421a08d2f924558056c8a382017ec37f56010e9 (diff)
parent4a741df757cf6b1d1b4c0e8c875c34b650f46167 (diff)
downloaddexon-bb366271fe33cf87b462dc5a25ac6c448ac6d2e1.tar
dexon-bb366271fe33cf87b462dc5a25ac6c448ac6d2e1.tar.gz
dexon-bb366271fe33cf87b462dc5a25ac6c448ac6d2e1.tar.bz2
dexon-bb366271fe33cf87b462dc5a25ac6c448ac6d2e1.tar.lz
dexon-bb366271fe33cf87b462dc5a25ac6c448ac6d2e1.tar.xz
dexon-bb366271fe33cf87b462dc5a25ac6c448ac6d2e1.tar.zst
dexon-bb366271fe33cf87b462dc5a25ac6c448ac6d2e1.zip
Merge pull request #14686 from fjl/hexutil-json-type-error
common/hexutil: wrap errors in json.UnmarshalTypeError
Diffstat (limited to 'common/hexutil/hexutil.go')
-rw-r--r--common/hexutil/hexutil.go25
1 files changed, 15 insertions, 10 deletions
diff --git a/common/hexutil/hexutil.go b/common/hexutil/hexutil.go
index 6b128ae36..582a67c22 100644
--- a/common/hexutil/hexutil.go
+++ b/common/hexutil/hexutil.go
@@ -32,7 +32,6 @@ package hexutil
import (
"encoding/hex"
- "errors"
"fmt"
"math/big"
"strconv"
@@ -41,17 +40,23 @@ import (
const uintBits = 32 << (uint64(^uint(0)) >> 63)
var (
- ErrEmptyString = errors.New("empty hex string")
- ErrMissingPrefix = errors.New("missing 0x prefix for hex data")
- ErrSyntax = errors.New("invalid hex")
- ErrEmptyNumber = errors.New("hex number has no digits after 0x")
- ErrLeadingZero = errors.New("hex number has leading zero digits after 0x")
- ErrOddLength = errors.New("hex string has odd length")
- ErrUint64Range = errors.New("hex number does not fit into 64 bits")
- ErrUintRange = fmt.Errorf("hex number does not fit into %d bits", uintBits)
- ErrBig256Range = errors.New("hex number does not fit into 256 bits")
+ ErrEmptyString = &decError{"empty hex string"}
+ ErrSyntax = &decError{"invalid hex string"}
+ ErrMissingPrefix = &decError{"hex string without 0x prefix"}
+ ErrOddLength = &decError{"hex string of odd length"}
+ ErrEmptyNumber = &decError{"hex string \"0x\""}
+ ErrLeadingZero = &decError{"hex number with leading zero digits"}
+ ErrUint64Range = &decError{"hex number > 64 bits"}
+ ErrUintRange = &decError{fmt.Sprintf("hex number > %d bits", uintBits)}
+ ErrBig256Range = &decError{"hex number > 256 bits"}
)
+type decError struct{ msg string }
+
+func (err decError) Error() string {
+ return string(err.msg)
+}
+
// Decode decodes a hex string with 0x prefix.
func Decode(input string) ([]byte, error) {
if len(input) == 0 {