-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
75 lines (59 loc) · 2.03 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package uint256
import (
"errors"
"strconv"
)
var (
ErrEmptyString = errors.New("empty hex string")
ErrSyntax = errors.New("invalid hex string")
ErrRange = errors.New("number out of range")
ErrMissingPrefix = errors.New("hex string without 0x prefix")
ErrEmptyNumber = errors.New("hex string \"0x\"")
ErrLeadingZero = errors.New("hex number with leading zero digits")
ErrBig256Range = errors.New("hex number > 256 bits")
ErrBadBufferLength = errors.New("bad ssz buffer length")
ErrBadEncodedLength = errors.New("bad ssz encoded length")
ErrInvalidBase = errors.New("invalid base")
ErrInvalidBitSize = errors.New("invalid bit size")
)
type u256Error struct {
fn string // function name
input string
err error
}
func (e *u256Error) Error() string {
return e.fn + ": " + e.input + ": " + e.err.Error()
}
func (e *u256Error) Unwrap() error {
return e.err
}
func errEmptyString(fn, input string) error {
return &u256Error{fn: fn, input: input, err: ErrEmptyString}
}
func errSyntax(fn, input string) error {
return &u256Error{fn: fn, input: input, err: ErrSyntax}
}
func errMissingPrefix(fn, input string) error {
return &u256Error{fn: fn, input: input, err: ErrMissingPrefix}
}
func errEmptyNumber(fn, input string) error {
return &u256Error{fn: fn, input: input, err: ErrEmptyNumber}
}
func errLeadingZero(fn, input string) error {
return &u256Error{fn: fn, input: input, err: ErrLeadingZero}
}
func errRange(fn, input string) error {
return &u256Error{fn: fn, input: input, err: ErrRange}
}
func errBig256Range(fn, input string) error {
return &u256Error{fn: fn, input: input, err: ErrBig256Range}
}
func errBadBufferLength(fn, input string) error {
return &u256Error{fn: fn, input: input, err: ErrBadBufferLength}
}
func errInvalidBase(fn string, base int) error {
return &u256Error{fn: fn, input: strconv.Itoa(base), err: ErrInvalidBase}
}
func errInvalidBitSize(fn string, bitSize int) error {
return &u256Error{fn: fn, input: strconv.Itoa(bitSize), err: ErrInvalidBitSize}
}