{"record":{"id":"cde6a8680bd03324","repo":"nodejs/node","slug":"expected-token-r-got-r","errorCode":null,"errorMessage":"expected token %r, got %r","messagePattern":"expected token %r, got %r","errorType":"exception","errorClass":"TemplateSyntaxError","httpStatus":null,"severity":"error","filePath":"tools/inspector_protocol/jinja2/lexer.py","lineNumber":381,"sourceCode":"\n    def close(self):\n        \"\"\"Close the stream.\"\"\"\n        self.current = Token(self.current.lineno, TOKEN_EOF, '')\n        self._iter = None\n        self.closed = True\n\n    def expect(self, expr):\n        \"\"\"Expect a given token type and return it.  This accepts the same\n        argument as :meth:`jinja2.lexer.Token.test`.\n        \"\"\"\n        if not self.current.test(expr):\n            expr = describe_token_expr(expr)\n            if self.current.type is TOKEN_EOF:\n                raise TemplateSyntaxError('unexpected end of template, '\n                                          'expected %r.' % expr,\n                                          self.current.lineno,\n                                          self.name, self.filename)\n            raise TemplateSyntaxError(\"expected token %r, got %r\" %\n                                      (expr, describe_token(self.current)),\n                                      self.current.lineno,\n                                      self.name, self.filename)\n        try:\n            return self.current\n        finally:\n            next(self)\n\n\ndef get_lexer(environment):\n    \"\"\"Return a lexer which is probably cached.\"\"\"\n    key = (environment.block_start_string,\n           environment.block_end_string,\n           environment.variable_start_string,\n           environment.variable_end_string,\n           environment.comment_start_string,\n           environment.comment_end_string,\n           environment.line_statement_prefix,","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/inspector_protocol/jinja2/lexer.py#L363-L399","documentation":"TokenStream.expect(expr) raised when the current token is not EOF but does not match the expected expression — the parser got a real token of the wrong kind. This is the non-EOF sibling of error 609 and indicates a structural syntax mistake rather than truncation.","triggerScenarios":"Malformed tag such as {% if %}{% endif %} missing the condition, {% for in items %} missing the loop variable, stray operators, or any place the grammar required one token type but received another.","commonSituations":"Hand-editing a tag and dropping a required operand; using a tag outside its grammar (e.g. {% else %} without a matching {% if %}/{% for %}).","solutions":["Read the message: it states which token was expected and which was actually found at the given line.","Fix the offending tag to supply the required token (e.g. add the condition expression after {% if %}).","Cross-check the construct against Jinja2's tag grammar in the docs."],"exampleFix":"{# before #}\n{% if %}...{% endif %}\n\n{# after #}\n{% if user.is_admin %}...{% endif %}","handlingStrategy":"validation","validationCode":"from jinja2 import Environment\n\ndef lint_template(source: str):\n    env = Environment()\n    env.parse(source)  # raises TemplateSyntaxError with line number on malformed input","typeGuard":null,"tryCatchPattern":"from jinja2.exceptions import TemplateSyntaxError\ntry:\n    env.parse(source)\nexcept TemplateSyntaxError as e:\n    log.error('template syntax at %s:%s: %s', name, e.lineno, e.message)","preventionTips":["Run env.parse over every template during CI.","Cross-check tag usage against the Jinja2 tag grammar in the docs.","Add a pre-commit hook that parses changed templates."],"tags":["jinja2","syntax","parser","unexpected-token"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}