-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy patherrors.go
More file actions
131 lines (105 loc) · 3.31 KB
/
errors.go
File metadata and controls
131 lines (105 loc) · 3.31 KB
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
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
type InvalidExtensionError struct {
err error
}
func NewInvalidExtensionError(msg string) error {
return NewInvalidExtensionErrorf(msg)
}
func NewInvalidExtensionErrorf(msg string, args ...interface{}) error {
return InvalidExtensionError{
err: fmt.Errorf(msg, args...),
}
}
func (e InvalidExtensionError) Unwrap() error {
return e.err
}
func (e InvalidExtensionError) Error() string {
return e.err.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 {
err error
}
func NewOutdatedExtensionError(msg string) error {
return NewOutdatedExtensionErrorf(msg)
}
func NewOutdatedExtensionErrorf(msg string, args ...interface{}) error {
return OutdatedExtensionError{
err: fmt.Errorf(msg, args...),
}
}
func (e OutdatedExtensionError) Unwrap() error {
return e.err
}
func (e OutdatedExtensionError) Error() string {
return e.err.Error()
}
func IsOutdatedExtensionError(err error) bool {
return errors.As(err, &OutdatedExtensionError{})
}
// NoValidChildBlockError is a sentinel error when the case where a certain block has
// no valid child.
type NoValidChildBlockError struct {
err error
}
func NewNoValidChildBlockError(msg string) error {
return NoValidChildBlockError{
err: fmt.Errorf(msg),
}
}
func NewNoValidChildBlockErrorf(msg string, args ...interface{}) error {
return NewNoValidChildBlockError(fmt.Sprintf(msg, args...))
}
func (e NoValidChildBlockError) Unwrap() error {
return e.err
}
func (e NoValidChildBlockError) Error() string {
return e.err.Error()
}
func IsNoValidChildBlockError(err error) bool {
return errors.As(err, &NoValidChildBlockError{})
}
// UnknownBlockError is a sentinel error indicating that a certain block
// has not been ingested yet.
type UnknownBlockError struct {
blockID flow.Identifier
err error
}
// WrapAsUnknownBlockError wraps a given error as UnknownBlockError
func WrapAsUnknownBlockError(blockID flow.Identifier, err error) error {
return UnknownBlockError{
blockID: blockID,
err: fmt.Errorf("block %v has not been processed yet: %w", blockID, err),
}
}
func NewUnknownBlockError(blockID flow.Identifier) error {
return UnknownBlockError{
blockID: blockID,
err: fmt.Errorf("block %v has not been processed yet", blockID),
}
}
func (e UnknownBlockError) Unwrap() error { return e.err }
func (e UnknownBlockError) Error() string { return e.err.Error() }
func IsUnknownBlockError(err error) bool {
var e UnknownBlockError
return errors.As(err, &e)
}