{"record":{"id":"099eb6dfb1c65465","repo":"nodejs/node","slug":"chunk-after-expression","errorCode":null,"errorMessage":"chunk after expression","messagePattern":"chunk after expression","errorType":"exception","errorClass":"TemplateSyntaxError","httpStatus":null,"severity":"error","filePath":"tools/inspector_protocol/jinja2/environment.py","lineNumber":626,"sourceCode":"        True\n\n        Per default the return value is converted to `None` if the\n        expression returns an undefined value.  This can be changed\n        by setting `undefined_to_none` to `False`.\n\n        >>> env.compile_expression('var')() is None\n        True\n        >>> env.compile_expression('var', undefined_to_none=False)()\n        Undefined\n\n        .. versionadded:: 2.1\n        \"\"\"\n        parser = Parser(self, source, state='variable')\n        exc_info = None\n        try:\n            expr = parser.parse_expression()\n            if not parser.stream.eos:\n                raise TemplateSyntaxError('chunk after expression',\n                                          parser.stream.current.lineno,\n                                          None, None)\n            expr.set_environment(self)\n        except TemplateSyntaxError:\n            exc_info = sys.exc_info()\n        if exc_info is not None:\n            self.handle_exception(exc_info, source_hint=source)\n        body = [nodes.Assign(nodes.Name('result', 'store'), expr, lineno=1)]\n        template = self.from_string(nodes.Template(body, lineno=1))\n        return TemplateExpression(template, undefined_to_none)\n\n    def compile_templates(self, target, extensions=None, filter_func=None,\n                          zip='deflated', log_function=None,\n                          ignore_errors=True, py_compile=False):\n        \"\"\"Finds all the templates the loader can find, compiles them\n        and stores them in `target`.  If `zip` is `None`, instead of in a\n        zipfile, the templates will be stored in a directory.\n        By default a deflate zip algorithm is used. To switch to","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/inspector_protocol/jinja2/environment.py#L608-L644","documentation":"Raised by Environment.compile_expression (jinja2 environment.py) when the source string parses to one valid expression but has leftover tokens after it. compile_expression expects exactly a single expression; after parsing, the stream must be at end-of-stream. Any trailing token — a second expression, an operator, or stray text — is rejected.","triggerScenarios":"Passing `'a b'`, `'a; b'`, `'a + b c'`, `'a == b =='`, or any source with two expressions / dangling operators to compile_expression; concatenating user fragments without separators; treating compile_expression like a full-statement compiler.","commonSituations":"Building a rule/eval engine on top of compile_expression and joining fragments with spaces; passing a Jinja statement (`{% if %}...`) instead of an expression; trailing whitespace is fine but trailing tokens are not.","solutions":["Pass exactly one expression; split compound inputs into multiple compile_expression calls.","Strip trailing junk / normalize user input before compiling.","For full Jinja syntax use Environment.compile / from_string instead of compile_expression."],"exampleFix":"# before\nexpr = env.compile_expression('a b')\n# after\nexpr = env.compile_expression('a')\nexpr2 = env.compile_expression('b')","handlingStrategy":"validation","validationCode":"from jinja2 import Environment\nenv = Environment()\ndef compile_single(source):\n    # reject compound / multi-expression input early\n    if any(sep in source for sep in (';', ',')) and source.count(' ') > 1:\n        raise ValueError('compile_expression takes exactly one expression')\n    return env.compile_expression(source)","typeGuard":null,"tryCatchPattern":"try:\n    expr = env.compile_expression(source)\nexcept Exception as e:\n    if 'chunk after expression' in str(e):\n        raise ValueError('provide exactly one expression: %r' % source)\n    raise","preventionTips":["Pass exactly one expression to compile_expression.","Normalize/split user-supplied fragments before compiling.","Use Environment.compile / from_string for full Jinja statements."],"tags":["jinja2","expression","syntax","compile"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}