LykosAI/StabilityMatrix · error · InvalidOperationException

Expected opening brace.

Error message

Expected opening brace.

What it means

PromptSyntaxBuilder.ParseWildcard throws InvalidOperationException when the next token is not scoped 'punctuation.definition.wildcard.begin.prompt' (the '{' that starts a wildcard). Like ParseArray, it assumes the caller verified the token, so this signals a tokenizer/dispatch mismatch.

Solutions

  1. Verify the token at the failure point is '{' with scope 'punctuation.definition.wildcard.begin.prompt'.
  2. Update the TextMate grammar scope definitions for wildcard braces.
  3. Correct ParseNode's lookahead so ParseWildcard is only entered after confirming a wildcard-begin token.
  4. Catch the exception at the parse entry point and convert it to a descriptive parse failure.
Defensive patterns

Strategy: try-catch

Validate before calling

var tokens = tokenizer.Tokenize(prompt);
if (tokens.All(t => !t.Scopes.Contains("punctuation.definition.wildcard.begin.prompt")) && prompt.Contains('{'))
    throw new ArgumentException("Prompt contains braces the grammar does not classify as wildcards.");

Type guard

bool IsWildcardBeginToken(Token t) => t?.Scopes?.Contains("punctuation.definition.wildcard.begin.prompt") == true;

Try / catch

try { var node = builder.Parse(prompt); }
catch (InvalidOperationException ex) { ShowUserFriendlyParseError(ex.Message); }

Prevention

When it happens

Trigger: ParseNode dispatching to ParseWildcard when the consumed token lacks the wildcard-begin scope, or the grammar classifying '{' differently than expected.

Common situations: Prompt text with braces used for weighting or non-wildcard syntax, grammar version drift changing scope labels, malformed wildcard templates.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12). Data as JSON: /api/errors/9c670853c483b923. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix.Core/Models/PromptSyntax/PromptSyntaxBuilder.cs:346

                break;
            }
            else
            {
                node.Elements.Add(ParseNode()); // Recursively parse nested nodes.
            }
        }

        return node;
    }

    private WildcardNode ParseWildcard()
    {
        var openBraceToken = ConsumeToken(); // Consume the '{'
        if (
            openBraceToken is null
            || !openBraceToken.Scopes.Contains("punctuation.definition.wildcard.begin.prompt")
        )
            throw new InvalidOperationException("Expected opening brace.");

        var node = new WildcardNode
        {
            Span = new TextSpan(openBraceToken.StartIndex, 0), // Set start index
        };

        while (MoreTokens())
        {
            var nextToken = PeekToken();
            if (nextToken is null)
                break;

            if (nextToken.Scopes.Contains("punctuation.definition.wildcard.end.prompt"))
            {
                ConsumeToken(); // Consume the '}'
                node.EndIndex = nextToken.EndIndex;
                break;
            }

View on GitHub (pinned to af93d6ef57)