{"record":{"id":"68f314ea533db95c","repo":"tui-cs/Terminal.Gui","slug":"wrong-number-of-values-expected-3-or-4-decimal-in","errorCode":null,"errorMessage":"Wrong number of values. Expected 3 or 4 decimal integers. Got {rangeCount}.","messagePattern":"Wrong number of values\\. Expected 3 or 4 decimal integers\\. Got (.+?)\\.","errorType":"validation","errorClass":"ColorParseException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Drawing/Color/Color.Formatting.cs","lineNumber":401,"sourceCode":"                                        out ReadOnlySpan<char> gSpan,\n                                        out ReadOnlySpan<char> bSpan\n                                       );\n                        ReadOnlySpan<char> aSpan = valuesSubstring [valueRanges [3]];\n\n                        if (!aSpan.IsAllAsciiDigits ())\n                        {\n                            throw new ColorParseException (\n                                                           in originalString,\n                                                           \"Value was not composed entirely of decimal digits.\",\n                                                           in aSpan,\n                                                           nameof (A)\n                                                          );\n                        }\n\n                        return new Color (int.Parse (rSpan), int.Parse (gSpan), int.Parse (bSpan), int.Parse (aSpan));\n                    }\n                default:\n                    throw new ColorParseException (\n                                                   in originalString,\n                                                   $\"Wrong number of values. Expected 3 or 4 decimal integers. Got {rangeCount}.\",\n                                                   in originalString\n                                                  );\n            }\n\n            [Pure]\n            [SkipLocalsInit]\n            static void ParseRgbValues (\n                in ReadOnlySpan<char> valuesString,\n                in Span<Range> valueComponentRanges,\n                in ReadOnlySpan<char> originalString,\n                out ReadOnlySpan<char> rSpan,\n                out ReadOnlySpan<char> gSpan,\n                out ReadOnlySpan<char> bSpan\n            )\n            {\n                rSpan = valuesString [valueComponentRanges [0]];","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drawing/Color/Color.Formatting.cs#L383-L419","documentation":"Thrown by ParseRgbaFormat when the rgb()/rgba() string, after splitting on commas, does not yield exactly 3 or 4 value ranges. The message reports the actual count found. Only rgb(r,g,b) and rgb(r,g,b,a) (3 or 4 components) are valid; anything else hits the default switch arm.","triggerScenarios":"Passing \"rgb(1,2)\" (2 values), \"rgb(1,2,3,4,5)\" (5 values), \"rgb(1,,2,3)\" (empty segment shifts count), or a trailing comma \"rgb(1,2,3,)\".","commonSituations":"Dynamically building rgb strings with the wrong number of components, stray/missing commas from string interpolation, or copying malformed CSS.","solutions":["Construct rgb strings with exactly 3 (or 4 for alpha) integer components.","Split and validate the component count is 3 or 4 before calling Parse.","Use Color.TryParse to degrade gracefully on malformed input."],"exampleFix":"// before\nColor c = Color.Parse($\"rgb({string.Join(',', values)})\");\n\n// after\nif (values.Length is 3 or 4)\n    Color c = Color.Parse($\"rgb({string.Join(',', values)})\");","handlingStrategy":"validation","validationCode":"int n = values.Length;\nif (n is not 3 and not 4) return fallbackColor;","typeGuard":"static bool HasValidRgbArity(string[] parts) => parts.Length is 3 or 4;","tryCatchPattern":"try { c = Color.Parse(rgbString); } catch (ColorParseException) { c = fallback; }","preventionTips":["Build rgb() strings with exactly 3 or 4 comma-separated components.","Watch for empty segments caused by trailing/leading commas.","Prefer Color.TryParse over Parse for dynamic input."],"tags":["color","parsing","rgb","validation","format-exception"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}