{"record":{"id":"dd508f63a710df35","repo":"LykosAI/StabilityMatrix","slug":"expected-closing-parenthesis","errorCode":null,"errorMessage":"Expected closing parenthesis.","messagePattern":"Expected closing parenthesis\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Models/PromptSyntax/PromptSyntaxBuilder.cs","lineNumber":218,"sourceCode":"                if (weightToken is null || !weightToken.Scopes.Contains(\"constant.numeric\"))\n                {\n                    throw new InvalidOperationException(\"Expected numeric weight value.\");\n                }\n\n                // Consume the weight token.\n                node.Weight = ParseNumber();\n            }\n            // We're supposed to check `punctuation.definition.array.end.prompt` here, textmate is not parsing it\n            // separately always with current tmLanguage grammar, so ALSO use `meta.structure.weight.prompt` for now\n            // We check this AFTER `punctuation.separator.weight.prompt` to avoid consuming the ':'\n            else if (\n                nextToken.Scopes.Contains(\"punctuation.definition.array.end.prompt\")\n                || nextToken.Scopes.Contains(\"meta.structure.weight.prompt\")\n            )\n            {\n                // Verify contents\n                if (GetTextSubstring(nextToken) != \")\")\n                    throw new InvalidOperationException(\"Expected closing parenthesis.\");\n\n                ConsumeToken(); // Consume the ')'\n                node.EndIndex = nextToken.EndIndex; // Set end index\n                break;\n            }\n            else\n            {\n                // It's part of the content.\n                node.Content.Add(ParseNode()); // Recursively parse nested nodes.\n            }\n        }\n\n        return node;\n    }\n\n    private NetworkNode ParseNetwork()\n    {\n        var beginNetworkToken = ConsumeToken();","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Models/PromptSyntax/PromptSyntaxBuilder.cs#L200-L236","documentation":"Thrown by ParseParenthesized when the token that should terminate a weighted group reaches the closing-token check but is not literally the ')' character, even though its scopes matched 'punctuation.definition.array.end.prompt' or 'meta.structure.weight.prompt'. The parser verifies the actual substring text, not just scopes, before consuming the closer.","triggerScenarios":"A token whose scopes claim an end punctuation but whose text is not ')' — e.g. a tokenizer/grammar version mismatch where a different close symbol is scoped as array end, or malformed nesting such as '(text:1.2]' or '(text:1.2}'.","commonSituations":"Textmate grammar updates in the tokenizer whose scope names changed relative to what PromptSyntaxBuilder expects; prompts written with mismatched bracket types copied from other syntaxes.","solutions":["Use a matching ')' to close the parenthesized group","Check the tokenizer/grammar (textmate) version matches what PromptSyntaxBuilder expects for scope names","Verify the prompt has balanced, same-type brackets: '(a:1.1)' not '(a:1.1]'","Catch InvalidOperationException and log the offending prompt string for diagnosis"],"exampleFix":"// before\nvar prompt = \"(sharp focus:1.2]\";\n// after\nvar prompt = \"(sharp focus:1.2)\";","handlingStrategy":"try-catch","validationCode":"bool UsesMatchingBrackets(string prompt) => !prompt.Contains(\"]\") && !prompt.Contains(\"}\") || prompt.Count(c => c=='(') == prompt.Count(c => c==')');","typeGuard":"null","tryCatchPattern":"try { var node = builder.Parse(prompt); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"closing parenthesis\")) { // log prompt and tokenizer scope info; report bracket mismatch }","preventionTips":["Use only '(' to close weighted groups, never ']' or '}'","Keep the tokenizer/textmate grammar version aligned with the parser","Sanitize prompts containing mixed bracket styles before parsing","Log the failing prompt text to diagnose grammar mismatches"],"tags":["parser","prompt-syntax","closing-parenthesis","tokenizer"],"backgroundTag":"invalid-argument-format","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}