github.com/koko1123/flow-go-1@v0.29.6/state/protocol/errors.go (about) 1 package protocol 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/koko1123/flow-go-1/model/flow" 8 "github.com/koko1123/flow-go-1/state" 9 ) 10 11 var ( 12 // ErrNoPreviousEpoch is a sentinel error returned when a previous epoch is 13 // queried from a snapshot within the first epoch after the root block. 14 ErrNoPreviousEpoch = fmt.Errorf("no previous epoch exists") 15 16 // ErrNextEpochNotSetup is a sentinel error returned when the next epoch 17 // has not been set up yet. 18 ErrNextEpochNotSetup = fmt.Errorf("next epoch has not yet been set up") 19 20 // ErrEpochNotCommitted is a sentinel error returned when the epoch has 21 // not been committed and information is queried that is only accessible 22 // in the EpochCommitted phase. 23 ErrEpochNotCommitted = fmt.Errorf("queried info from EpochCommit event before it was emitted") 24 25 // ErrSealingSegmentBelowRootBlock is a sentinel error returned for queries 26 // for a sealing segment below the root block. 27 ErrSealingSegmentBelowRootBlock = fmt.Errorf("cannot query sealing segment below root block") 28 29 // ErrClusterNotFound is a sentinel error returns for queries for a cluster 30 ErrClusterNotFound = fmt.Errorf("could not find cluster") 31 ) 32 33 type IdentityNotFoundError struct { 34 NodeID flow.Identifier 35 } 36 37 func (e IdentityNotFoundError) Error() string { 38 return fmt.Sprintf("identity not found (%x)", e.NodeID) 39 } 40 41 func IsIdentityNotFound(err error) bool { 42 var errIdentityNotFound IdentityNotFoundError 43 return errors.As(err, &errIdentityNotFound) 44 } 45 46 type InvalidBlockTimestampError struct { 47 error 48 } 49 50 func (e InvalidBlockTimestampError) Unwrap() error { 51 return e.error 52 } 53 54 func (e InvalidBlockTimestampError) Error() string { 55 return e.error.Error() 56 } 57 58 func IsInvalidBlockTimestampError(err error) bool { 59 var errInvalidTimestampError InvalidBlockTimestampError 60 return errors.As(err, &errInvalidTimestampError) 61 } 62 63 func NewInvalidBlockTimestamp(msg string, args ...interface{}) error { 64 return InvalidBlockTimestampError{ 65 error: fmt.Errorf(msg, args...), 66 } 67 } 68 69 // InvalidServiceEventError indicates an invalid service event was processed. 70 type InvalidServiceEventError struct { 71 error 72 } 73 74 func (e InvalidServiceEventError) Unwrap() error { 75 return e.error 76 } 77 78 func IsInvalidServiceEventError(err error) bool { 79 var errInvalidServiceEventError InvalidServiceEventError 80 return errors.As(err, &errInvalidServiceEventError) 81 } 82 83 // NewInvalidServiceEventError returns an invalid service event error. Since all invalid 84 // service events indicate an invalid extension, the service event error is wrapped in 85 // the invalid extension error at construction. 86 func NewInvalidServiceEventError(msg string, args ...interface{}) error { 87 return state.NewInvalidExtensionErrorf( 88 "cannot extend state with invalid service event: %w", 89 InvalidServiceEventError{ 90 error: fmt.Errorf(msg, args...), 91 }, 92 ) 93 }