{"record":{"id":"ab72de928871a955","repo":"AtsushiSakai/PythonRobotics","slug":"self-name-invalid-transition-src-state-nam","errorCode":null,"errorMessage":"|{self._name}| invalid transition: <{src_state.name}> : [{event}]","messagePattern":"\\|(.+?)\\| invalid transition: <(.+?)> : \\[(.+?)\\]","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"MissionPlanning/StateMachine/state_machine.py","lineNumber":161,"sourceCode":"            return state if isinstance(state, State) else self._get_state(state)\n\n        def get_callable(func):\n            return func if callable(func) else getattr(self._model, func, None)\n\n        src_state_obj = get_state_obj(src_state)\n        dst_state_obj = get_state_obj(dst_state)\n\n        guard_func = get_callable(guard) if guard else None\n        action_func = get_callable(action) if action else None\n        self._transition_table[(src_state_obj.name, event)] = (\n            dst_state_obj,\n            guard_func,\n            action_func,\n        )\n\n    def state_transition(self, src_state: State, event: str):\n        if (src_state.name, event) not in self._transition_table:\n            raise ValueError(\n                f\"|{self._name}| invalid transition: <{src_state.name}> : [{event}]\"\n            )\n\n        dst_state, guard, action = self._transition_table[(src_state.name, event)]\n\n        def call_guard(guard):\n            if callable(guard):\n                return guard()\n            else:\n                return True\n\n        def call_action(action):\n            if callable(action):\n                action()\n\n        if call_guard(guard):\n            call_action(action)\n            if src_state.name != dst_state.name:","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/AtsushiSakai/PythonRobotics/blob/1fe4fb980f6a12fe21c3c33d2b4da97a52c9154d/MissionPlanning/StateMachine/state_machine.py#L143-L179","documentation":"Raised by StateMachine.state_transition when the (current state name, event) pair is not present in the transition table. The machine only accepts events explicitly declared for the current state; anything else is invalid by design.","triggerScenarios":"Calling machine.process('some_event') while in a state that has no transition registered for that event, e.g. sending 'start' while already in the started state.","commonSituations":"Event-driven robots where events arrive out of order (duplicates, late events), or forgetting to register all valid (state, event) pairs when defining the machine.","solutions":["Check machine.generate_plantuml() or the transition table to see which events are valid in the current state.","Register the missing transition with add_transition (or your machine's builder) if the event should be legal.","Debounce/queue events so they are only dispatched in states that accept them."],"exampleFix":"# before\nmachine.process('charge')  # not defined from current state\n\n# after\nmachine.add_transition(current_state, 'charge', charging_state)\nmachine.process('charge')","handlingStrategy":"validation","validationCode":"valid_events = {ev for (st, ev) in machine._transition_table if st == machine._state.name}\nif event not in valid_events:\n    raise ValueError(f'{event} not valid in state {machine._state.name}')","typeGuard":null,"tryCatchPattern":"try:\n    machine.process(event)\nexcept ValueError as e:\n    if 'invalid transition' in str(e):\n        log.warning('ignored stale event %s in state %s', event, machine._state.name)\n    else:\n        raise","preventionTips":["Inspect generate_plantuml() output to know legal events per state.","Centralize event dispatch through a queue that filters per-state valid events."],"tags":["state-machine","transition-validation","event-driven"],"backgroundTag":"invalid-state-transition","analyzedSha":"1fe4fb980f6a12fe21c3c33d2b4da97a52c9154d","analyzedAt":"2026-08-28T13:23:33.733Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}