{"record":{"id":"078b9ac21a35234b","repo":"antlr/antlr4","slug":"the-specified-lexer-action-type-is-not-valid","errorCode":null,"errorMessage":"The specified lexer action type {} is not valid.","messagePattern":"The specified lexer action type (.+?) is not valid\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"runtime/Python3/src/antlr4/atn/ATNDeserializer.py","lineNumber":444,"sourceCode":"    POP_MODE = 4    #The type of a {@link LexerPopModeAction} action.\n    PUSH_MODE = 5   #The type of a {@link LexerPushModeAction} action.\n    SKIP = 6        #The type of a {@link LexerSkipAction} action.\n    TYPE = 7        #The type of a {@link LexerTypeAction} action.\n\n    actionFactories = [ lambda data1, data2: LexerChannelAction(data1),\n                        lambda data1, data2: LexerCustomAction(data1, data2),\n                        lambda data1, data2: LexerModeAction(data1),\n                        lambda data1, data2: LexerMoreAction.INSTANCE,\n                        lambda data1, data2: LexerPopModeAction.INSTANCE,\n                        lambda data1, data2: LexerPushModeAction(data1),\n                        lambda data1, data2: LexerSkipAction.INSTANCE,\n                        lambda data1, data2: LexerTypeAction(data1)\n                      ]\n\n    def lexerActionFactory(self, type:int, data1:int, data2:int):\n\n        if type > len(self.actionFactories) or self.actionFactories[type] is None:\n            raise Exception(\"The specified lexer action type \" + str(type) + \" is not valid.\")\n        else:\n            return self.actionFactories[type](data1, data2)\n","sourceCodeStart":426,"sourceCodeEnd":447,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Python3/src/antlr4/atn/ATNDeserializer.py#L426-L447","documentation":"lexerActionFactory() decodes lexer action codes (channel, custom, mode, more, popMode, pushMode, skip, type) when a lexer ATN executes or deserializes action transitions. An unknown action type code raises this Exception — in practice always a symptom of serialized data deserialized by an incompatible runtime version, since the code table is fixed per format version.","triggerScenarios":"deserialize() (or first lex) reading a lexer action opcode beyond the supported table because the data stream is misaligned or from a different serialized-version grammar (e.g. a grammar with lexer actions generated by a newer tool).","commonSituations":"Grammars using -> channel/mode/type/skip/custom actions combined with tool/runtime version mismatch; stale generated lexer files; partial regeneration (new lexer, old parser or vice versa).","solutions":["Regenerate lexer and parser together with the tool version matching the runtime.","Upgrade the runtime package to the tool's version (pip install antlr4-python3-runtime==<tool version>).","Clean build outputs so no pre-regeneration lexer artifact survives."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    lexer = MyLexer(stream)\nexcept Exception as e:\n    if 'lexer action type' in str(e):\n        raise RuntimeError('lexer ATN uses actions this runtime cannot decode: regenerate with matching versions')\n    raise","preventionTips":["Regenerate lexer and parser together in one command with one tool version","After adding lexer actions (channel/mode/type/custom), regenerate and redeploy both artifacts","Pin the runtime version equal to the tool version"],"tags":["antlr4","python","lexer","version-mismatch","deserialization"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}