Replika.Error.InvalidTransitionError exception (Replika v0.1.0)

View Source

Raised when attempting an event transition that isn't defined for the current state.

This error provides detailed information about:

  • The current state of the FSM
  • The event that was attempted
  • Any arguments passed to the event

Examples

try do
  Unit.AccessState.new()
  |> Unit.AccessState.pickup_card()
  |> Unit.AccessState.pickup_card()  # Can't pickup card when already have one
rescue
  e in InvalidTransitionError ->
    # e.state == :has_id_card
    # e.event == :pickup_card
    # e.args == []
    IO.puts(e.message)
end

Troubleshooting

This error usually indicates one of these issues:

  1. Calling an event in the wrong state (state machine logic error)
  2. Missing a state definition for a necessary transition
  3. Missing an event definition for a valid use case

Review your state machine definition and ensure all valid state transitions are properly defined.

Summary

Types

t()

@type t() :: %Replika.Error.InvalidTransitionError{
  __exception__: true,
  args: list(),
  event: atom(),
  message: String.t(),
  state: atom()
}