-
Notifications
You must be signed in to change notification settings - Fork 178
/
errors.go
89 lines (73 loc) · 2.6 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package state
import (
"errors"
"fmt"
)
var (
// ErrUnknownSnapshotReference indicates that the reference point for a queried
// snapshot cannot be resolved. The reference point is either a height above the
// finalized boundary, or a block ID that does not exist in the state.
ErrUnknownSnapshotReference = errors.New("reference block of the snapshot is not resolvable")
)
// InvalidExtensionError is an error for invalid extension of the state. An invalid
// extension is distinct from outdated or unverifiable extensions, in that it indicates
// a malicious input.
type InvalidExtensionError struct {
error
}
func NewInvalidExtensionError(msg string) error {
return NewInvalidExtensionErrorf(msg)
}
func NewInvalidExtensionErrorf(msg string, args ...interface{}) error {
return InvalidExtensionError{
error: fmt.Errorf(msg, args...),
}
}
func (e InvalidExtensionError) Unwrap() error {
return e.error
}
// IsInvalidExtensionError returns whether the given error is an InvalidExtensionError error
func IsInvalidExtensionError(err error) bool {
return errors.As(err, &InvalidExtensionError{})
}
// OutdatedExtensionError is an error for the extension of the state being outdated.
// Being outdated doesn't mean it's invalid or not.
// Knowing whether an outdated extension is an invalid extension or not would
// take more state queries.
type OutdatedExtensionError struct {
error
}
func NewOutdatedExtensionError(msg string) error {
return NewOutdatedExtensionErrorf(msg)
}
func NewOutdatedExtensionErrorf(msg string, args ...interface{}) error {
return OutdatedExtensionError{
error: fmt.Errorf(msg, args...),
}
}
func (e OutdatedExtensionError) Unwrap() error {
return e.error
}
func IsOutdatedExtensionError(err error) bool {
return errors.As(err, &OutdatedExtensionError{})
}
// UnverifiableExtensionError represents a state extension (block) which cannot be
// verified at the moment. For example, it does not connect to the finalized state,
// or an entity referenced within the payload is unknown.
// Unlike InvalidExtensionError, this error is only used when the failure CANNOT be
// attributed to a malicious input, therefore this error can be treated as a benign failure.
type UnverifiableExtensionError struct {
error
}
func NewUnverifiableExtensionError(msg string, args ...interface{}) error {
return UnverifiableExtensionError{
error: fmt.Errorf(msg, args...),
}
}
func (e UnverifiableExtensionError) Unwrap() error {
return e.error
}
func IsUnverifiableExtensionError(err error) bool {
var errUnverifiableExtensionError UnverifiableExtensionError
return errors.As(err, &errUnverifiableExtensionError)
}