{"record":{"id":"1d01a96a69f57e32","repo":"tui-cs/Terminal.Gui","slug":"text-was-too-short-to-be-any-possible-supported-fo","errorCode":null,"errorMessage":"Text was too short to be any possible supported format.","messagePattern":"Text was too short to be any possible supported format\\.","errorType":"validation","errorClass":"ColorParseException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Drawing/Color/Color.Formatting.cs","lineNumber":280,"sourceCode":"    [SkipLocalsInit]\n    public static Color Parse (ReadOnlySpan<char> text, IFormatProvider? formatProvider = null)\n    {\n        return text switch\n        {\n            // Null string or empty span provided\n            { IsEmpty: true } when formatProvider is null =>\n                throw new ColorParseException (in text, \"The text provided was null or empty.\", in text),\n\n            // A valid ICustomColorFormatter was specified and the text wasn't null or empty\n            { IsEmpty: false } when formatProvider is ICustomColorFormatter f => f.Parse (text),\n\n            // Input string is only whitespace\n            { Length: > 0 } when text.IsWhiteSpace () =>\n                throw new ColorParseException (in text, \"The text provided consisted of only whitespace characters.\", in text),\n\n            // Any string too short to possibly be any supported format.\n            { Length: > 0 and < 3 } =>\n                throw new ColorParseException (in text, \"Text was too short to be any possible supported format.\", in text),\n\n            // The various hexadecimal cases\n            ['#', ..] hexString => hexString switch\n            {\n                // #RGB\n                ['#', var rChar, var gChar, var bChar] chars when chars [1..]\n                    .IsAllAsciiHexDigits () =>\n                        new Color (\n                            byte.Parse ([rChar, rChar], NumberStyles.HexNumber),\n                            byte.Parse ([gChar, gChar], NumberStyles.HexNumber),\n                            byte.Parse ([bChar, bChar], NumberStyles.HexNumber)\n                        ),\n\n                // #ARGB\n                ['#', var aChar, var rChar, var gChar, var bChar] chars when chars [1..]\n                    .IsAllAsciiHexDigits () =>\n                        new Color (\n                            byte.Parse ([rChar, rChar], NumberStyles.HexNumber),","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drawing/Color/Color.Formatting.cs#L262-L298","documentation":"Thrown by Color.Parse(ReadOnlySpan<char>) when the input length is between 1 and 2 inclusive. The shortest valid color representation is at least 3 characters long (e.g. a named color), so anything shorter cannot possibly match any supported format. It is a ColorParseException (FormatException). The string overload has its own equivalent guard for text shorter than 3 characters.","triggerScenarios":"Calling Color.Parse(\"a\") or Color.Parse(\"#1\") on a span of length 1 or 2 when no ICustomColorFormatter is supplied.","commonSituations":"Truncated color strings from config, a '#' prefix typed alone, or partial/incomplete user input passed straight to the parser.","solutions":["Check input length >= 3 before calling Parse, or use TryParse.","Use Color.TryParse(...) to avoid the throw and apply a fallback color.","Provide an ICustomColorFormatter via the formatProvider argument if you need a custom short format."],"exampleFix":"// before\nColor c = Color.Parse(token.AsSpan());\n\n// after\nColor c = token.Length >= 3 && Color.TryParse(token.AsSpan(), null, out Color parsed)\n    ? parsed\n    : default;","handlingStrategy":"validation","validationCode":"if (text.AsSpan().Length < 3) return fallbackColor;","typeGuard":"static bool IsParsableColorLength(ReadOnlySpan<char> s) => s.Length >= 3;","tryCatchPattern":"try { c = Color.Parse(s.AsSpan()); } catch (ColorParseException) { c = fallback; }","preventionTips":["Reject color strings shorter than 3 characters up front.","Use Color.TryParse to avoid exceptions on short input.","Provide an ICustomColorFormatter if you genuinely need a custom short format."],"tags":["color","parsing","validation","format-exception"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}