{"record":{"id":"9fe97852cd22059b","repo":"AtsushiSakai/PythonRobotics","slug":"invalid-event-event","errorCode":null,"errorMessage":"Invalid event: {event}","messagePattern":"Invalid event: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"MissionPlanning/StateMachine/state_machine.py","lineNumber":241,"sourceCode":"    def get_current_state(self):\n        return self._state\n\n    def process(self, event: str) -> None:\n        \"\"\"Process an event in the state machine.\n\n        Args:\n            event: Event name.\n\n        Example:\n            >>> machine.process(\"start\")\n        \"\"\"\n        if self._state is None:\n            raise ValueError(\"State machine is not initialized\")\n\n        if self._has_event(event):\n            self.state_transition(self._state, event)\n        else:\n            raise ValueError(f\"Invalid event: {event}\")\n\n    def generate_plantuml(self) -> str:\n        \"\"\"Generate PlantUML state diagram representation of the state machine.\n\n        Returns:\n            str: PlantUML state diagram code.\n        \"\"\"\n        if self._state is None:\n            raise ValueError(\"State machine is not initialized\")\n\n        plant_uml = [\"@startuml\"]\n        plant_uml.append(\"[*] --> \" + self._state.name)\n\n        # Generate transitions\n        for (src_state, event), (\n            dst_state,\n            guard,\n            action,","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/AtsushiSakai/PythonRobotics/blob/1fe4fb980f6a12fe21c3c33d2b4da97a52c9154d/MissionPlanning/StateMachine/state_machine.py#L223-L259","documentation":"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.","triggerScenarios":"Calling process('stoped') (typo) or an event string never used in any add_transition call.","commonSituations":"String event names from message queues or UI handlers that drift from the registered event vocabulary, or typos in event constants.","solutions":["Compare the event string against registered events (inspect the transition table keys).","Centralize event names as constants/enums instead of raw strings.","Register a handler/transition for the event if it should be supported."],"exampleFix":"# before\nmachine.process('stoped')\n\n# after\nmachine.process(EVENT_STOP)  # 'stop'","handlingStrategy":"validation","validationCode":"registered = {ev for (_, ev) in machine._transition_table}\nassert event in registered, f'unknown event {event!r}; known: {sorted(registered)}'","typeGuard":null,"tryCatchPattern":"try:\n    machine.process(event)\nexcept ValueError as e:\n    if str(e).startswith('Invalid event'):\n        log.warning('dropping unknown event %s', event)\n    else:\n        raise","preventionTips":["Define events as constants/enums; never pass ad-hoc strings.","Log unknown events instead of crashing in event-driven systems."],"tags":["state-machine","event-validation","typos"],"backgroundTag":"unknown-event-name","analyzedSha":"1fe4fb980f6a12fe21c3c33d2b4da97a52c9154d","analyzedAt":"2026-08-28T13:23:33.733Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}