Tinder / StateMachine

A Kotlin and Swift DSL for finite state machine
Other
1.96k stars 128 forks source link

Throw exception with meaningful error description in case of missing state definition. #15

Closed pchmielowski closed 5 years ago

pchmielowski commented 5 years ago

When a state definition is missing, exception is thrown with message: Required value is null. This fix adds more meaningful error message.

An example of missing state definition:

            private val stateMachine = StateMachine.create<String, Int, Nothing> {
                initialState(STATE_A)
                state(STATE_A) {
                    on(EVENT_1) {
                        transitionTo(STATE_B)
                    }
                }
                // Missing STATE_B definition.
            }

Error is thrown here:

stateMachine.transition(EVENT_1) // transition to `STATE_B` which is not handled.