github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/compute/store/errors.go (about)

     1  package store
     2  
     3  import "fmt"
     4  
     5  // ErrNilExecution is returned when the execution is nil
     6  type ErrNilExecution struct{}
     7  
     8  func NewErrNilExecution() ErrNilExecution {
     9  	return ErrNilExecution{}
    10  }
    11  
    12  func (e ErrNilExecution) Error() string {
    13  	return "execution is nil"
    14  }
    15  
    16  // ErrExecutionNotFound is returned when the execution is not found
    17  type ErrExecutionNotFound struct {
    18  	ExecutionID string
    19  }
    20  
    21  func NewErrExecutionNotFound(id string) ErrExecutionNotFound {
    22  	return ErrExecutionNotFound{ExecutionID: id}
    23  }
    24  
    25  func (e ErrExecutionNotFound) Error() string {
    26  	return "execution not found: " + e.ExecutionID
    27  }
    28  
    29  // ErrExecutionNotFound is returned when the execution is not found
    30  type ErrExecutionsNotFoundForShard struct {
    31  	ShardID string
    32  }
    33  
    34  func NewErrExecutionsNotFound(id string) ErrExecutionsNotFoundForShard {
    35  	return ErrExecutionsNotFoundForShard{ShardID: id}
    36  }
    37  
    38  func (e ErrExecutionsNotFoundForShard) Error() string {
    39  	return "no executions found for shard: " + e.ShardID
    40  }
    41  
    42  // ErrExecutionHistoryNotFound is returned when the execution is not found
    43  type ErrExecutionHistoryNotFound struct {
    44  	ExecutionID string
    45  }
    46  
    47  func NewErrExecutionHistoryNotFound(id string) ErrExecutionHistoryNotFound {
    48  	return ErrExecutionHistoryNotFound{ExecutionID: id}
    49  }
    50  
    51  func (e ErrExecutionHistoryNotFound) Error() string {
    52  	return "no history found for execution: " + e.ExecutionID
    53  }
    54  
    55  // ErrExecutionAlreadyExists is returned when an execution already exists
    56  type ErrExecutionAlreadyExists struct {
    57  	ExecutionID string
    58  }
    59  
    60  func NewErrExecutionAlreadyExists(id string) ErrExecutionAlreadyExists {
    61  	return ErrExecutionAlreadyExists{ExecutionID: id}
    62  }
    63  
    64  func (e ErrExecutionAlreadyExists) Error() string {
    65  	return "execution already exists: " + e.ExecutionID
    66  }
    67  
    68  // ErrInvalidExecutionState is returned when an execution is in an invalid state.
    69  type ErrInvalidExecutionState struct {
    70  	ExecutionID string
    71  	Actual      ExecutionState
    72  	Expected    ExecutionState
    73  }
    74  
    75  func NewErrInvalidExecutionState(id string, actual ExecutionState, expected ExecutionState) ErrInvalidExecutionState {
    76  	return ErrInvalidExecutionState{ExecutionID: id, Actual: actual, Expected: expected}
    77  }
    78  
    79  func (e ErrInvalidExecutionState) Error() string {
    80  	return "execution " + e.ExecutionID + " is in state " + e.Actual.String() + " but expected " + e.Expected.String()
    81  }
    82  
    83  // ErrInvalidExecutionVersion is returned when an execution has an invalid version.
    84  type ErrInvalidExecutionVersion struct {
    85  	ExecutionID string
    86  	Actual      int
    87  	Expected    int
    88  }
    89  
    90  func NewErrInvalidExecutionVersion(id string, actual int, expected int) ErrInvalidExecutionVersion {
    91  	return ErrInvalidExecutionVersion{ExecutionID: id, Actual: actual, Expected: expected}
    92  }
    93  
    94  func (e ErrInvalidExecutionVersion) Error() string {
    95  	return fmt.Sprintf("execution %s has version %d but expected %d", e.ExecutionID, e.Actual, e.Expected)
    96  }
    97  
    98  // ErrExecutionAlreadyTerminal is returned when an execution is already in terminal state and cannot be updated.
    99  type ErrExecutionAlreadyTerminal struct {
   100  	ExecutionID string
   101  	Actual      ExecutionState
   102  	NewState    ExecutionState
   103  }
   104  
   105  func NewErrExecutionAlreadyTerminal(id string, actual ExecutionState, newState ExecutionState) ErrExecutionAlreadyTerminal {
   106  	return ErrExecutionAlreadyTerminal{ExecutionID: id, Actual: actual, NewState: newState}
   107  }
   108  
   109  func (e ErrExecutionAlreadyTerminal) Error() string {
   110  	return fmt.Sprintf("execution %s is in terminal state %s and cannot transition to %s",
   111  		e.ExecutionID, e.Actual.String(), e.NewState.String())
   112  }