-
Notifications
You must be signed in to change notification settings - Fork 179
/
errors.go
145 lines (118 loc) · 4.02 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package state
import (
"errors"
"fmt"
"github.com/onflow/flow-go/model/flow"
)
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)
}
// NoChildBlockError is returned where a certain block has no valid child.
// Since all blocks are validated before being inserted to the state, this is
// equivalent to have no stored child.
type NoChildBlockError struct {
error
}
func NewNoChildBlockError(msg string) error {
return NoChildBlockError{
error: fmt.Errorf(msg),
}
}
func NewNoChildBlockErrorf(msg string, args ...interface{}) error {
return NewNoChildBlockError(fmt.Sprintf(msg, args...))
}
func (e NoChildBlockError) Unwrap() error {
return e.error
}
func IsNoChildBlockError(err error) bool {
return errors.As(err, &NoChildBlockError{})
}
// UnknownBlockError is a sentinel error indicating that a certain block
// has not been ingested yet.
type UnknownBlockError struct {
blockID flow.Identifier
error
}
// WrapAsUnknownBlockError wraps a given error as UnknownBlockError
func WrapAsUnknownBlockError(blockID flow.Identifier, err error) error {
return UnknownBlockError{
blockID: blockID,
error: fmt.Errorf("block %v has not been processed yet: %w", blockID, err),
}
}
func NewUnknownBlockError(blockID flow.Identifier) error {
return UnknownBlockError{
blockID: blockID,
error: fmt.Errorf("block %v has not been processed yet", blockID),
}
}
func (e UnknownBlockError) Unwrap() error { return e.error }
func IsUnknownBlockError(err error) bool {
var e UnknownBlockError
return errors.As(err, &e)
}