{"record":{"id":"cf7ccd669c194ca7","repo":"alibaba/COLA","slug":"cannot-fire-event-event-on-current-state-s","errorCode":null,"errorMessage":"Cannot fire event [${event}] on current state [${sourceState}] with context [${context}]","messagePattern":"Cannot fire event \\[(.+?)\\] on current state \\[(.+?)\\] with context \\[(.+?)\\]","errorType":"exception","errorClass":"TransitionFailException","httpStatus":null,"severity":"error","filePath":"cola-components/cola-component-statemachine/src/main/java/com/alibaba/cola/statemachine/builder/AlertFailCallback.java","lineNumber":15,"sourceCode":"package com.alibaba.cola.statemachine.builder;\n\nimport com.alibaba.cola.statemachine.exception.TransitionFailException;\n\n/**\n * Alert fail callback, throw an {@code TransitionFailException}\n *\n * @author 龙也\n * @date 2022/9/15 12:02 PM\n */\npublic class AlertFailCallback<S, E, C> implements FailCallback<S, E, C> {\n\n    @Override\n    public void onFail(S sourceState, E event, C context) {\n        throw new TransitionFailException(\n            \"Cannot fire event [\" + event + \"] on current state [\" + sourceState + \"] with context [\" + context + \"]\"\n        );\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/alibaba/COLA/blob/352e1a867538d9cd40e1b11e4028fa652fc97557/cola-components/cola-component-statemachine/src/main/java/com/alibaba/cola/statemachine/builder/AlertFailCallback.java#L1-L20","documentation":"AlertFailCallback is the default failure callback of the COLA state machine. When fireEvent() is invoked with an event that has no accepted transition from the machine's current state, onFail() throws this StateMachineException with the event, source state, and context. It signals an illegal/undefined event-state combination.","triggerScenarios":"fireEvent(sourceState, event, context) where no transition registered for (sourceState, event), or the transition exists but its condition rejected the context.","commonSituations":"Sending events in the wrong order (e.g. paying before creating); missing transition definitions in the builder; external inputs triggering events the state machine graph doesn't cover.","solutions":["Register a custom FailCallback (via builder) to log/recover instead of throwing","Check current state before firing: only send the event if a transition for (state, event) exists","Add the missing transition in the builder for the (sourceState, event) combination","Catch StateMachineException at the call site and treat it as an invalid business operation"],"exampleFix":"// before\nstateMachine.fireEvent(currentState, event, context); // throws when event invalid\n\n// after\ntry {\n    stateMachine.fireEvent(currentState, event, context);\n} catch (StateMachineException e) {\n    log.warn(\"Illegal event {} for state {}\", event, currentState);\n}","handlingStrategy":"try-catch","validationCode":"// pre-check: ensure a transition exists by catching at fire time is standard,\n// but you can validate event ordering in business code before firing\nassertAllowedEvent(currentState, event); // app-level whitelist of (state,event) pairs","typeGuard":null,"tryCatchPattern":"try {\n    stateMachine.fireEvent(sourceState, event, context);\n} catch (StateMachineException e) {\n    if (e.getMessage().startsWith(\"Cannot fire event\")) {\n        // log and reject the business operation as invalid\n    } else {\n        throw e;\n    }\n}","preventionTips":["Maintain a (state,event) whitelist mirroring the machine definition","Set a custom FailCallback for graceful handling","Add all required transitions in the builder","Enforce correct event ordering in business workflow code"],"tags":["statemachine","invalid-state-transition","event"],"backgroundTag":"invalid-state-transition","analyzedSha":"352e1a867538d9cd40e1b11e4028fa652fc97557","analyzedAt":"2026-09-08T00:46:23.972Z","contentChangedAt":"2026-09-08T00:46:23.972Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}