Skip to content

Commit

Permalink
shift: Add KVs to invalid transition type error
Browse files Browse the repository at this point in the history
  • Loading branch information
echarrod committed Aug 22, 2024
1 parent 82b228b commit a8e9b79
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ var ErrUnknownStatus = errors.New("unknown status", j.C("ERR_198a4c2d8a654b17"))
// registered with the FSM.
var ErrInvalidStateTransition = errors.New("invalid state transition", j.C("ERR_be8211db784bfb67"))

// ErrInvalidType indicates that the provided request type isn't valid can't be
// ErrInvalidType indicates that the provided request type isn't valid, and can't be
// used for the requested transition.
var ErrInvalidType = errors.New("invalid type", j.C("ERR_baf1a1f2e99951ec"))
2 changes: 1 addition & 1 deletion shift.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (fsm *GenFSM[T]) UpdateTx(ctx context.Context, tx *sql.Tx, from Status, to
return nil, errors.Wrap(ErrUnknownStatus, "unknown 'to' status", j.MKV{"from": fmt.Sprintf("%v", from), "to": fmt.Sprintf("%v", to)})
}
if !sameType(t.req, updater) {
return nil, errors.Wrap(ErrInvalidType, "updater can't be used for this transition")
return nil, errors.Wrap(ErrInvalidType, "updater can't be used for this transition", j.MKV{"from": fmt.Sprintf("%v", from), "to": fmt.Sprintf("%v", to)})
}
f, ok := fsm.states[from.ShiftStatus()]
if !ok {
Expand Down
7 changes: 7 additions & 0 deletions shift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,13 @@ func TestGenFSM_Update(t *testing.T) {
expErr: shift.ErrInvalidStateTransition,
expKVs: j.MKS{"from": fmt.Sprintf("%v", StatusComplete), "to": fmt.Sprintf("%v", StatusUpdate)},
},
{
name: "Invalid Type",
from: StatusInit,
to: StatusComplete,
expErr: shift.ErrInvalidType,
expKVs: j.MKS{"from": fmt.Sprintf("%v", StatusInit), "to": fmt.Sprintf("%v", StatusComplete)},
},
{
name: "Unknown 'from' status",
from: unknownShiftStatus,
Expand Down

0 comments on commit a8e9b79

Please sign in to comment.