{"record":{"id":"003efc6d16f19933","repo":"spectreconsole/spectre.console","slug":"invalid-rgb-color-rgb-ex-message","errorCode":null,"errorMessage":"Invalid RGB color '{rgb}'. {ex.Message}","messagePattern":"Invalid RGB 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":"ParseRgbColor caught an exception converting the component strings to bytes (e.g. non-numeric, out-of-byte-range overflow). The inner exception message is appended, e.g. for `[rgb(255,a,0)]` or `[rgb(300,0,0)]`.","triggerScenarios":"An `rgb(...)` part whose components aren't parseable bytes: non-numeric characters, or values outside 0-255 that overflow Convert.ToInt32→byte cast.","commonSituations":"Feeding floating-point or percentage values like `rgb(50%,50%,50%)`; values >255 from unclamped math; localized decimal separators.","solutions":["Use three integer components each in 0-255, e.g. rgb(255,128,0)","Clamp and round floats: (byte)Math.Round(Math.Clamp(v,0,255))","Validate with a regex like ^rgb\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3})\\)$"],"exampleFix":"// before\nAnsiMarkup.Parse(\"[rgb(255,a,0)]text[/]\");\n\n// after\nAnsiMarkup.Parse(\"[rgb(255,160,0)]text[/]\");","handlingStrategy":"validation","validationCode":"public static bool IsValidRgb(string token)\n{\n    var m = Regex.Match(token, @\"^rgb\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3})\\)$\");\n    return m.Success && m.Groups.Cast<Group>().Skip(1).All(g => int.Parse(g.Value) is >= 0 and <= 255);\n}","typeGuard":null,"tryCatchPattern":"try { AnsiMarkup.Parse(markup); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Invalid RGB color\"))\n{ /* clamp components to 0-255 and rebuild as rgb(r,g,b) */ }","preventionTips":["Use integer components in 0-255 only (no %, no decimals)","Clamp float values before converting to byte","Prefer #rrggbb for generated colors to sidestep rgb() parsing"],"tags":["markup","color","rgb","parsing","spectre-console"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}