-
Notifications
You must be signed in to change notification settings - Fork 179
/
errors.go
90 lines (72 loc) · 2.46 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
package protocol
import (
"errors"
"fmt"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state"
)
var (
// ErrNoPreviousEpoch is a sentinel error returned when a previous epoch is
// queried from a snapshot within the first epoch after the root block.
ErrNoPreviousEpoch = fmt.Errorf("no previous epoch exists")
// ErrNextEpochNotSetup is a sentinel error returned when the next epoch
// has not been set up yet.
ErrNextEpochNotSetup = fmt.Errorf("next epoch has not yet been set up")
// ErrEpochNotCommitted is a sentinel error returned when the epoch has
// not been committed and information is queried that is only accessible
// in the EpochCommitted phase.
ErrEpochNotCommitted = fmt.Errorf("queried info from EpochCommit event before it was emitted")
)
type IdentityNotFoundError struct {
NodeID flow.Identifier
}
func (e IdentityNotFoundError) Error() string {
return fmt.Sprintf("identity not found (%x)", e.NodeID)
}
func IsIdentityNotFound(err error) bool {
var errIdentityNotFound IdentityNotFoundError
return errors.As(err, &errIdentityNotFound)
}
type InvalidBlockTimestampError struct {
err error
}
func (e InvalidBlockTimestampError) Unwrap() error {
return e.err
}
func (e InvalidBlockTimestampError) Error() string {
return e.err.Error()
}
func IsInvalidBlockTimestampError(err error) bool {
var errInvalidTimestampError InvalidBlockTimestampError
return errors.As(err, &errInvalidTimestampError)
}
func NewInvalidBlockTimestamp(msg string, args ...interface{}) error {
return InvalidBlockTimestampError{
err: fmt.Errorf(msg, args...),
}
}
// InvalidServiceEventError indicates an invalid service event was processed.
type InvalidServiceEventError struct {
err error
}
func (e InvalidServiceEventError) Unwrap() error {
return e.err
}
func (e InvalidServiceEventError) Error() string {
return e.err.Error()
}
func IsInvalidServiceEventError(err error) bool {
var errInvalidServiceEventError InvalidServiceEventError
return errors.As(err, &errInvalidServiceEventError)
}
// NewInvalidServiceEventError returns an invalid service event error. Since all invalid
// service events indicate an invalid extension, the service event error is wrapped in
// the invalid extension error at construction.
func NewInvalidServiceEventError(msg string, args ...interface{}) error {
return state.NewInvalidExtensionErrorf(
"cannot extend state with invalid service event: %w",
InvalidServiceEventError{
err: fmt.Errorf(msg, args...),
},
)
}