java.lang.IllegalStateException if StateMachine doesn't contain description of toState #56
Open
Description
I have final state (ERROR) which hasn't any transitions or specific actions. Should I describe it anyway in empty state<TaskStateType.ERROR>
branch?
Now I miss it so I receive
java.lang.IllegalStateException: Missing definition for state Error!
because Error is absent in graph.stateDefinitions
and com.tinder.StateMachine#notifyOnEnter
method fails with such exception.
My state machine definition:
StateMachine.create<TaskStateType, StateEventType, TaskStateHandler> {
initialState(TaskStateType.New)
state<TaskStateType.New> {
on<StateEventType.OnWait> {
dontTransition()
}
on<StateEventType.OnError> {
transitionTo(TaskStateType.Error, handlerFactory.findHandlerByEvent(EventType.ERROR))
}
}
// TaskStateType.Error is missed here
onTransition {
val transition = it as? StateMachine.Transition.Valid
transition.sideEffect?.handle(context)
}
}
Need I change it to:
StateMachine.create<TaskStateType, StateEventType, TaskStateHandler> {
initialState(TaskStateType.New)
state<TaskStateType.New> {
on<StateEventType.OnWait> {
dontTransition()
}
on<StateEventType.OnError> {
transitionTo(TaskStateType.Error, handlerFactory.findHandlerByEvent(EventType.ERROR))
}
}
state<TaskStateType.Error> {
// do nothing
}
onTransition {
val transition = it as? StateMachine.Transition.Valid
transition.sideEffect?.handle(context)
}
}
It looks pretty ugly. May be I define something wrong so I need your help :-)
Metadata
Assignees
Labels
No labels