{"record":{"id":"93da053b7e7cd729","repo":"tui-cs/Terminal.Gui","slug":"the-text-provided-consisted-of-only-whitespace-cha","errorCode":null,"errorMessage":"The text provided consisted of only whitespace characters.","messagePattern":"The text provided consisted of only whitespace characters\\.","errorType":"validation","errorClass":"ColorParseException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Drawing/Color/Color.Formatting.cs","lineNumber":276,"sourceCode":"    ///     with an inner <see cref=\"FormatException\"/> if <paramref name=\"text\"/> was unable\n    ///     to be successfully parsed as a <see cref=\"Color\"/>, for any reason.\n    /// </exception>\n    [Pure]\n    [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","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drawing/Color/Color.Formatting.cs#L258-L294","documentation":"Thrown by Color.Parse(ReadOnlySpan<char>) when the input is non-empty but consists entirely of whitespace characters (spaces, tabs, etc.). It surfaces as a ColorParseException, which derives from FormatException. No supported color format (#RGB, rgb(...), named colors) can be whitespace-only, so the parser rejects it outright before attempting any format match. The string overload guards earlier via ArgumentException.ThrowIfNullOrWhiteSpace, so this path is mainly hit through the span-based Parse/TryParse entry points.","triggerScenarios":"Calling Color.Parse(\"   \".AsSpan()) or Color.TryParse(\" \\t \".AsSpan(), null, out _) with a span that is non-empty yet only whitespace. Also reached when an ICustomColorFormatter is not supplied and the span is whitespace.","commonSituations":"Theme/configuration JSON values that contain stray spaces instead of a color, user input that was trimmed down to spaces, or copied color strings with leading/trailing whitespace that replaced the real value.","solutions":["Trim the input and reject empty/whitespace before parsing: if (string.IsNullOrWhiteSpace(s)) return fallback;","Prefer Color.TryParse(...) which returns false instead of throwing for any parse failure.","Validate explicitly: if (text.AsSpan().IsWhiteSpace()) handle invalid input."],"exampleFix":"// before\nColor c = Color.Parse(userInput.AsSpan());\n\n// after\nif (!Color.TryParse(userInput.AsSpan(), null, out Color c))\n{\n    c = Color.White; // safe default\n}","handlingStrategy":"validation","validationCode":"if (text.AsSpan().IsEmpty || text.AsSpan().IsWhiteSpace()) return fallbackColor;","typeGuard":"static bool IsParsableColorText(ReadOnlySpan<char> s) => !s.IsEmpty && !s.IsWhiteSpace() && s.Length >= 3;","tryCatchPattern":"try { c = Color.Parse(s.AsSpan()); } catch (ColorParseException) { c = fallback; } // prefer Color.TryParse instead","preventionTips":["Always trim and validate color strings before parsing.","Prefer Color.TryParse over Color.Parse for user-supplied input.","Treat empty/whitespace as invalid at the UI/config boundary."],"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"}