AtsushiSakai/PythonRobotics · error · ValueError

Invalid event: {event}

Error message

Invalid event: {event}

What it means

Raised by StateMachine.process when the event name is not registered anywhere in the machine's event set, so no state could possibly handle it. This differs from an invalid transition: the event itself is unknown to the machine.

Source

Thrown at MissionPlanning/StateMachine/state_machine.py:241

    def get_current_state(self):
        return self._state

    def process(self, event: str) -> None:
        """Process an event in the state machine.

        Args:
            event: Event name.

        Example:
            >>> machine.process("start")
        """
        if self._state is None:
            raise ValueError("State machine is not initialized")

        if self._has_event(event):
            self.state_transition(self._state, event)
        else:
            raise ValueError(f"Invalid event: {event}")

    def generate_plantuml(self) -> str:
        """Generate PlantUML state diagram representation of the state machine.

        Returns:
            str: PlantUML state diagram code.
        """
        if self._state is None:
            raise ValueError("State machine is not initialized")

        plant_uml = ["@startuml"]
        plant_uml.append("[*] --> " + self._state.name)

        # Generate transitions
        for (src_state, event), (
            dst_state,
            guard,
            action,

View on GitHub (pinned to 1fe4fb980f)

Solutions

  1. Compare the event string against registered events (inspect the transition table keys).
  2. Centralize event names as constants/enums instead of raw strings.
  3. Register a handler/transition for the event if it should be supported.

Example fix

# before
machine.process('stoped')

# after
machine.process(EVENT_STOP)  # 'stop'
Defensive patterns

Strategy: validation

Validate before calling

registered = {ev for (_, ev) in machine._transition_table}
assert event in registered, f'unknown event {event!r}; known: {sorted(registered)}'

Try / catch

try:
    machine.process(event)
except ValueError as e:
    if str(e).startswith('Invalid event'):
        log.warning('dropping unknown event %s', event)
    else:
        raise

Prevention

When it happens

Trigger: Calling process('stoped') (typo) or an event string never used in any add_transition call.

Common situations: String event names from message queues or UI handlers that drift from the registered event vocabulary, or typos in event constants.

Related errors


AI-assisted analysis of AtsushiSakai/PythonRobotics@1fe4fb980f (2026-08-28). Data as JSON: /api/errors/9fe97852cd22059b. Report an issue: GitHub.