Skip to content

Commit

Permalink
ensure GetTransition does not panic
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Mar 30, 2022
1 parent d977316 commit ca30e11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func withTransition(ctx context.Context, transition Transition) context.Context
// GetTransition returns the transition from the context.
// If there is no transition the returned value is empty.
func GetTransition(ctx context.Context) Transition {
return ctx.Value(transitionKey{}).(Transition)
tr, _ := ctx.Value(transitionKey{}).(Transition)
return tr
}

// ActionFunc describes a generic action function.
Expand Down
5 changes: 5 additions & 0 deletions statemachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1369,3 +1369,8 @@ func TestStateMachine_Firing_Concurrent(t *testing.T) {
wg.Wait()
assert.False(t, sm.Firing())
}

func TestGetTransition_ContextEmpty(t *testing.T) {
// It should not panic
GetTransition(context.Background())
}

0 comments on commit ca30e11

Please sign in to comment.