{"record":{"id":"4b1dafead0ec48f6","repo":"tui-cs/Terminal.Gui","slug":"the-text-provided-was-null-or-empty","errorCode":null,"errorMessage":"The text provided was null or empty.","messagePattern":"The text provided was null or empty\\.","errorType":"validation","errorClass":"ColorParseException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Drawing/Color/Color.Formatting.cs","lineNumber":269,"sourceCode":"    ///     <br/> Defaults to <see cref=\"CultureInfo.InvariantCulture\"/> if <see langword=\"null\"/>. <br/> If not null, must\n    ///     implement <see cref=\"ICustomColorFormatter\"/> or will be ignored and <see cref=\"CultureInfo.InvariantCulture\"/>\n    ///     will be used.\n    /// </param>\n    /// <returns>A <see cref=\"Color\"/> value equivalent to <paramref name=\"text\"/>, if parsing was successful.</returns>\n    /// <remarks>While <see cref=\"Color\"/> supports the alpha channel <see cref=\"A\"/>, Terminal.Gui does not.</remarks>\n    /// <exception cref=\"ArgumentException\">\n    ///     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 () =>","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drawing/Color/Color.Formatting.cs#L251-L287","documentation":"Thrown by Color.Parse(ReadOnlySpan<char>, IFormatProvider?) when the input span is empty (IsEmpty) and no custom formatProvider is supplied. This is the span-overload equivalent of 'you handed me nothing to parse'. An empty span cannot match any color format, so a ColorParseException is raised with the empty span as the bad value.","triggerScenarios":"Calling Color.Parse(ReadOnlySpan<char>.Empty), Color.Parse(\"\".AsSpan()), or passing a span that was sliced to zero length. Distinguished from error 98 because this is the span overload and triggers on empty (Length 0), not merely short.","commonSituations":"Slicing a span past its end; reading an empty field from a parsed token; passing default(ReadOnlySpan<char>) by mistake.","solutions":["Check text.IsEmpty before calling Parse and return a default/skip the parse.","Pass an ICustomColorFormatter as formatProvider — the {IsEmpty:false} when ICustomColorFormatter arm handles empty input by delegating to the formatter (though note it requires non-empty too; ensure your formatter handles empty).","Route user input through the string overload which gives the more specific 'too short' message for non-empty short strings."],"exampleFix":"// before\nColor c = Color.Parse (someSpan); // throws if someSpan.IsEmpty\n\n// after\nif (someSpan.IsEmpty) return Color.Default;\nColor c = Color.Parse (someSpan);","handlingStrategy":"validation","validationCode":"if (text.IsEmpty) return Color.Default;\nColor c = Color.Parse (text);","typeGuard":"static bool IsNonEmptySpan (ReadOnlySpan<char> s) => !s.IsEmpty;","tryCatchPattern":"try { return Color.Parse (text); }\ncatch (ColorParseException) { return Color.Default; }","preventionTips":["Check span.IsEmpty before parsing.","Prefer the string overload for user input to get the more specific 'too short' message.","Default the formatProvider to CultureInfo.InvariantCulture to avoid surprising branches."],"tags":["drawing","color","parsing","validation","span"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}