-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Problem:
It is a valid use case for a state machine to receive an event that is not relevant in the current state.
For example, in an elevator system, the event "Button pressed: Up" may be sent while the elevator is already in the "Going Up" state. Typically, such events should be safely ignored without impacting the program.
Current behavior:
- If a state does not explicitly handle an event, the state machine throws an exception, halting the program.
- A workaround exists by adding null actions for unhandled events to each state. While it solves the issue, it's not good approach for big state machines with many events.
Expected solution:
The state machine should silently ignore any event that is valid but not explicitly handled in the current state, without requiring a null action handler.
Additional context
The implementation should distinguish between two types of events:
- Valid but unhandled events — these should be ignored (e.g., "Button pressed: Up" while already going up).
- Invalid events — events that do not exist in the state machine at all. These should still trigger exceptions, as they indicate a programming error.
The solution must ensure that ignoring unhandled events does not mask programming mistakes (i.e. sending event with typo, as events are strings currently).