{"record":{"id":"36f139ae375a0a67","repo":"twigphp/Twig","slug":"unexpected-s","errorCode":null,"errorMessage":"Unexpected \"%s\".","messagePattern":"Unexpected \"(.+?)\"\\.","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/Lexer.php","lineNumber":670,"sourceCode":"\n    private function popState(): void\n    {\n        if (0 === \\count($this->states)) {\n            throw new \\LogicException('Cannot pop state without a previous state.');\n        }\n\n        $this->state = array_pop($this->states);\n    }\n\n    private function checkBrackets(string $code): void\n    {\n        // opening bracket\n        if (\\in_array($code, $this->openingBrackets, true)) {\n            $this->brackets[] = [$code, $this->lineno];\n        } elseif (\\in_array($code, $this->closingBrackets, true)) {\n            // closing bracket\n            if (!$this->brackets) {\n                throw new SyntaxError(\\sprintf('Unexpected \"%s\".', $code), $this->lineno, $this->source, columnno: $this->source->getColumn($this->cursor));\n            }\n\n            [$expect, $lineno] = array_pop($this->brackets);\n            if ($code !== str_replace($this->openingBrackets, $this->closingBrackets, $expect)) {\n                throw new SyntaxError(\\sprintf('Unclosed \"%s\".', $expect), $lineno, $this->source);\n            }\n        }\n    }\n}\n","sourceCodeStart":652,"sourceCodeEnd":680,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Lexer.php#L652-L680","documentation":"Inside an expression, a closing bracket (`)`, `]`, or `}`) appeared when the bracket stack was empty — there is no matching opening bracket. Twig reports the offending character with line and column via checkBrackets, which runs for every punctuation token in lexExpression.","triggerScenarios":"An extra `)` / `]` / `}` in a tag: e.g. `{{ foo) }}`, `{% if (x) %}` written as `{% if x) %}`, or a `}` inside `{{ }}` used literally without quoting. Also caused by a preceding unclosed-bracket removal that unbalanced the expression.","commonSituations":"Typos in arithmetic or function-call expressions; pasting PHP/JS expressions that use syntax Twig doesn't accept; literal braces in templates placed inside expression context instead of verbatim/raw blocks.","solutions":["Remove the extra closing bracket at the reported line/column.","Add the matching opening bracket if one was intended (e.g. `{{ foo(bar)) }}` → `{{ foo((bar)) }}` review).","Wrap literal braces in `{% verbatim %}` blocks instead of leaving them in expressions.","Re-check the whole expression — an earlier missing `(` often makes a later `)` look extra."],"exampleFix":"// before\n{{ items] }}\n\n// after\n{{ items }}","handlingStrategy":"validation","validationCode":"foreach (['(' => ')', '[' => ']', '{' => '}'] as $open => $close) {\n    if (preg_match('/\\{\\{[^}]*'.preg_quote($close, '/').'\\s*\\}\\}/', $code)) {\n        // candidate stray closer inside an expression; review before parsing\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    $twig->render($name, $context);\n} catch (\\Twig\\Error\\SyntaxError $e) {\n    log('Unexpected bracket at line '.$e->getTemplateLine());\n}","preventionTips":["Wrap literal braces/brackets in {% verbatim %} blocks.","Re-read the whole expression — an extra closer usually mirrors an earlier missing opener.","Use bracket-matching editor features when editing Twig expressions."],"tags":["lexer","brackets","unbalanced","twig"],"backgroundTag":"unbalanced-brackets","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}