{"record":{"id":"7562ffc06dbbc7eb","repo":"spectreconsole/spectre.console","slug":"could-not-find-color-part","errorCode":null,"errorMessage":"Could not find color '{part}'.","messagePattern":"Could not find color '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console.Ansi/AnsiMarkupTagParser.cs","lineNumber":10,"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","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console.Ansi/AnsiMarkupTagParser.cs#L1-L28","documentation":"After the `on` keyword, foreground is false so the part is expected to be a background color. When the part matches no known color name, is not a valid hex/rgb/integer, the parser reports 'Could not find color {part}.' This string is re-thrown by the public Parse.","triggerScenarios":"A background position holding an unrecognized token, e.g. `[red on purpel]` (typo), `[on notacolor]`, or `[on default default]` where the second 'default' after `on` is not a recognized color.","commonSituations":"Misspelled color name; using a decoration keyword (e.g. `bold`) in the background slot; expecting a custom color name that isn't registered.","solutions":["Use a color name present in ColorTable (standard names like red, blue, green, etc.)","Use `#rrggbb`, `rgb(r,g,b)`, or a 0-255 index for the background","Use `default` to leave the background unset","Double-check spelling and that the token comes after `on`"],"exampleFix":"// before\nAnsiMarkup.Parse(\"[red on purpel]text[/]\");\n\n// after\nAnsiMarkup.Parse(\"[red on purple]text[/]\");","handlingStrategy":"validation","validationCode":"// Validate a background token against known forms before embedding:\npublic static bool IsValidBgToken(string token) =>\n    ColorTable.GetColor(token) != null\n    || Regex.IsMatch(token, @\"^#[0-9A-Fa-f]{6}$\")\n    || Regex.IsMatch(token, @\"^rgb\\(\\d{1,3},\\d{1,3},\\d{1,3}\\)$\")\n    || token == \"default\";","typeGuard":null,"tryCatchPattern":"try { AnsiMarkup.Parse(markup); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Could not find color\"))\n{ /* replace unknown bg token with 'default' or a known name */ }","preventionTips":["Spell color names exactly as defined in ColorTable","Use hex or rgb forms to avoid name mismatches","Validate the part appears after `on` for backgrounds"],"tags":["markup","color","parsing","spectre-console"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}