{"record":{"id":"224c1510bc7943e8","repo":"nodejs/node","slug":"unexpected-s","errorCode":null,"errorMessage":"unexpected '%s'","messagePattern":"unexpected '(.+?)'","errorType":"exception","errorClass":"TemplateSyntaxError","httpStatus":null,"severity":"error","filePath":"tools/inspector_protocol/jinja2/lexer.py","lineNumber":681,"sourceCode":"                            data = m.group(idx + 1)\n                            if data or token not in ignore_if_empty:\n                                yield lineno, token, data\n                            lineno += data.count('\\n')\n\n                # strings as token just are yielded as it.\n                else:\n                    data = m.group()\n                    # update brace/parentheses balance\n                    if tokens == 'operator':\n                        if data == '{':\n                            balancing_stack.append('}')\n                        elif data == '(':\n                            balancing_stack.append(')')\n                        elif data == '[':\n                            balancing_stack.append(']')\n                        elif data in ('}', ')', ']'):\n                            if not balancing_stack:\n                                raise TemplateSyntaxError('unexpected \\'%s\\'' %\n                                                          data, lineno, name,\n                                                          filename)\n                            expected_op = balancing_stack.pop()\n                            if expected_op != data:\n                                raise TemplateSyntaxError('unexpected \\'%s\\', '\n                                                          'expected \\'%s\\'' %\n                                                          (data, expected_op),\n                                                          lineno, name,\n                                                          filename)\n                    # yield items\n                    if data or tokens not in ignore_if_empty:\n                        yield lineno, tokens, data\n                    lineno += data.count('\\n')\n\n                # fetch new position into new variable so that we can check\n                # if there is a internal parsing error which would result\n                # in an infinite loop\n                pos2 = m.end()","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/inspector_protocol/jinja2/lexer.py#L663-L699","documentation":"The lexer maintains a balancing_stack of expected closers as it sees { ( [. When it encounters }, ), or ] and the stack is empty, there is no matching opener — an unbalanced closing bracket — and it raises TemplateSyntaxError('unexpected \\'%s\\'').","triggerScenarios":"A stray ), ], or } inside a Jinja2 expression/tag, e.g. {{ foo) }}, {% if (a and b) } %}, or an extra closing bracket from editing.","commonSituations":"Deleting an opening bracket while leaving its closer; copy-paste that introduces an unmatched closer; converting function-call syntax.","solutions":["Find the stray closing bracket at the reported line and remove it or add its matching opener.","Balance every ( [ { with its ) ] } in expressions and macros calls."],"exampleFix":"{# before #}\n{{ format_name(user)) }}\n\n{# after #}\n{{ format_name(user) }}","handlingStrategy":"validation","validationCode":"def brackets_balanced(expr: str) -> bool:\n    pairs = {')': '(', ']': '[', '}': '{'}\n    stack = []\n    for ch in expr:\n        if ch in '([{':\n            stack.append(ch)\n        elif ch in pairs:\n            if not stack or stack.pop() != pairs[ch]:\n                return False\n    return not stack","typeGuard":null,"tryCatchPattern":"from jinja2.exceptions import TemplateSyntaxError\ntry:\n    env.parse(source)\nexcept TemplateSyntaxError as e:\n    log.error('unbalanced bracket at %s:%s', name, e.lineno)","preventionTips":["Pair-edit brackets: add the closer as soon as you open.","Use env.parse to validate expressions before rendering.","Use an editor that auto-pairs brackets."],"tags":["jinja2","syntax","lexer","unbalanced-brackets"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}