Skip to content

Automatically ignore valid but unhandled events in a state #12

@embeddedk8

Description

@embeddedk8

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:

  1. If a state does not explicitly handle an event, the state machine throws an exception, halting the program.
  2. 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:

  1. Valid but unhandled events — these should be ignored (e.g., "Button pressed: Up" while already going up).
  2. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions