Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalStateException if StateMachine doesn't contain description of toState #56

Open
ranetkaSt opened this issue Jan 12, 2023 · 1 comment

Comments

@ranetkaSt
Copy link

ranetkaSt commented Jan 12, 2023

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 :-)

@ranetkaSt ranetkaSt changed the title java.lang.IllegalStateException if StateMachine doesn't contain description of End state java.lang.IllegalStateException if StateMachine doesn't contain description of toState Jan 12, 2023
@tinder-tramesh
Copy link

Hmm, I believe at the moment, declaring an empty state block is the only way to represent a terminal state:

    state<TaskStateType.Error> {
        // No-op
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants