github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/mempool/errors.go (about)

     1  package mempool
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  // UnknownExecutionResultError indicates that the Execution Result is unknown
     9  type UnknownExecutionResultError struct {
    10  	err error
    11  }
    12  
    13  func NewUnknownExecutionResultError(msg string) error {
    14  	return NewUnknownExecutionResultErrorf(msg)
    15  }
    16  
    17  func NewUnknownExecutionResultErrorf(msg string, args ...interface{}) error {
    18  	return UnknownExecutionResultError{
    19  		err: fmt.Errorf(msg, args...),
    20  	}
    21  }
    22  
    23  func (e UnknownExecutionResultError) Unwrap() error {
    24  	return e.err
    25  }
    26  
    27  func (e UnknownExecutionResultError) Error() string {
    28  	return e.err.Error()
    29  }
    30  
    31  // IsUnknownExecutionResultError returns whether the given error is an UnknownExecutionResultError error
    32  func IsUnknownExecutionResultError(err error) bool {
    33  	var unknownExecutionResultError UnknownExecutionResultError
    34  	return errors.As(err, &unknownExecutionResultError)
    35  }
    36  
    37  // BelowPrunedThresholdError indicates that we are attempting to query or prune a mempool by a
    38  // key (typically block height or block view) which is lower than the lowest retained key threshold.
    39  // In other words, we have already pruned above the specified key value.
    40  type BelowPrunedThresholdError struct {
    41  	err error
    42  }
    43  
    44  func NewBelowPrunedThresholdErrorf(msg string, args ...interface{}) error {
    45  	return BelowPrunedThresholdError{
    46  		err: fmt.Errorf(msg, args...),
    47  	}
    48  }
    49  
    50  func (e BelowPrunedThresholdError) Unwrap() error {
    51  	return e.err
    52  }
    53  
    54  func (e BelowPrunedThresholdError) Error() string {
    55  	return e.err.Error()
    56  }
    57  
    58  // IsBelowPrunedThresholdError returns whether the given error is an BelowPrunedThresholdError error
    59  func IsBelowPrunedThresholdError(err error) bool {
    60  	var newIsBelowPrunedThresholdError BelowPrunedThresholdError
    61  	return errors.As(err, &newIsBelowPrunedThresholdError)
    62  }