{"record":{"id":"d00b3907be0de628","repo":"spectreconsole/spectre.console","slug":"could-not-parse-style","errorCode":null,"errorMessage":"Could not parse style.","messagePattern":"Could not parse style\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console.Ansi/AnsiMarkupTagParser.cs","lineNumber":13,"sourceCode":"namespace Spectre.Console;\n\ninternal static class AnsiMarkupTagParser\n{\n    public static (Style Style, Link? Link) Parse(string text)\n    {\n        var result = Parse(text, out var error);\n        if (error != null)\n        {\n            throw new InvalidOperationException(error);\n        }\n\n        return result ?? throw new InvalidOperationException(\"Could not parse style.\");\n    }\n\n    public static bool TryParse(string text, [NotNullWhen(true)] out (Style Style, Link?)? result)\n    {\n        result = Parse(text, out _);\n        return result != null;\n    }\n\n    private static (Style Style, Link? Link)? Parse(string text, out string? error)\n    {\n        var effectiveDecoration = (Decoration?)null;\n        var effectiveForeground = (Color?)null;\n        var effectiveBackground = (Color?)null;\n        var effectiveLink = (string?)null;\n\n        var parts = text.Split([' ']);\n        var foreground = true;\n        foreach (var part in parts)","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console.Ansi/AnsiMarkupTagParser.cs#L1-L31","documentation":"Defensive fallback in the public AnsiMarkupTagParser.Parse: the private Parse returned null but produced no error string, so the message 'Could not parse style.' is thrown. In the current implementation every null return path sets an error, so this branch is effectively unreachable.","triggerScenarios":"Not reproducible via the public API with current code: all failure paths populate the error string before returning null. It exists as a safety net against a future code path that returns null without setting error.","commonSituations":"Should never surface to a consumer. If seen, it indicates an internal regression where a Parse branch returns null without an error message.","solutions":["Report it as a library bug with the offending tag text and stack trace","Catch InvalidOperationException when rendering dynamic markup so a parse failure degrades gracefully","Use AnsiMarkupTagParser.TryParse (which returns bool) if you need non-throwing behavior"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Use the non-throwing TryParse where available:\nif (AnsiMarkupTagParser.TryParse(tag, out var parsed)) { /* use parsed */ }","typeGuard":null,"tryCatchPattern":"try { var style = AnsiMarkupTagParser.Parse(tag); }\ncatch (InvalidOperationException ex) when (ex.Message == \"Could not parse style.\")\n{ /* defensive/unreachable: report upstream, fall back to Style.Plain */ }","preventionTips":["Prefer AnsiMarkupTagParser.TryParse over Parse for robustness","Report an occurrence as a library regression with the offending tag","Wrap dynamic tag parsing in try/catch"],"tags":["markup","parsing","defensive","spectre-console"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}