{"record":{"id":"3e43896e45a95f5a","repo":"tui-cs/Terminal.Gui","slug":"provided-text-is-too-short-to-be-any-known-color-f","errorCode":null,"errorMessage":"Provided text is too short to be any known color format.","messagePattern":"Provided text is too short to be any known color format\\.","errorType":"validation","errorClass":"ColorParseException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Drawing/Color/Color.Formatting.cs","lineNumber":231,"sourceCode":"    /// <remarks>While <see cref=\"Color\"/> supports the alpha channel <see cref=\"A\"/>, Terminal.Gui does not.</remarks>\n    /// <exception cref=\"ArgumentNullException\">If <paramref name=\"text\"/> is <see langword=\"null\"/>.</exception>\n    /// <exception cref=\"ArgumentException\">\n    ///     If <paramref name=\"text\"/> is an empty string or consists of only whitespace\n    ///     characters.\n    /// </exception>\n    /// <exception cref=\"ColorParseException\">\n    ///     If thrown by\n    ///     <see cref=\"Parse(System.ReadOnlySpan{char},System.IFormatProvider?)\"/>.\n    /// </exception>\n    [Pure]\n    [SkipLocalsInit]\n    public static Color Parse (string? text, IFormatProvider? formatProvider = null)\n    {\n        ArgumentException.ThrowIfNullOrWhiteSpace (text, nameof (text));\n\n        if (text is { Length: < 3 } && formatProvider is null)\n        {\n            throw new ColorParseException (\n                                           text,\n                                           reason: \"Provided text is too short to be any known color format.\",\n                                           badValue: text\n                                          );\n        }\n\n        return Parse (text.AsSpan (), formatProvider ?? CultureInfo.InvariantCulture);\n    }\n\n    /// <summary>\n    ///     Converts the provided <see cref=\"ReadOnlySpan{T}\"/> of <see langword=\"char\"/> to a new <see cref=\"Color\"/>\n    ///     value.\n    /// </summary>\n    /// <param name=\"text\">\n    ///     The text to analyze. Formats supported are \"#RGB\", \"#RRGGBB\", \"#RGBA\", \"#AARRGGBB\", \"rgb(r,g,b)\",\n    ///     \"rgb(r,g,b,a)\", \"rgba(r,g,b)\", \"rgba(r,g,b,a)\", and any of the <see cref=\"ColorName16\"/> string values.\n    /// </param>\n    /// <param name=\"formatProvider\">","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drawing/Color/Color.Formatting.cs#L213-L249","documentation":"Thrown by Color.Parse(string?, IFormatProvider?) when the text is non-null/non-whitespace but shorter than 3 characters AND no custom formatProvider is supplied. Terminal.Gui's shortest valid color formats are 3 characters (a ColorName16 alias or '#XY'), so anything shorter cannot be valid; the error is raised eagerly in the string overload before delegating to the span-based parser.","triggerScenarios":"Calling Color.Parse(\"a\"), Color.Parse(\"#\"), Color.Parse(\"\"), or any 1-2 character input without an ICustomColorFormatter. Note ArgumentException.ThrowIfNullOrWhiteSpace already handles null/whitespace earlier, so this fires for short non-whitespace strings.","commonSituations":"Reading color values from a config/UI field without length validation; a truncated hex string; a user typing a partial color name.","solutions":["Provide a complete color string: '#RRGGBB', '#AARRGGBB', 'rgb(r,g,b)', 'rgba(r,g,b,a)', or a full ColorName16 name.","Validate length >= 3 (and ideally matches a known format) before calling Parse, or use Color.TryParse if available.","Pass an ICustomColorFormatter as formatProvider if you have a shorter custom encoding you want to decode yourself."],"exampleFix":"// before\nColor c = Color.Parse (userInput); // throws if userInput is \"#\"\n\n// after\nif (userInput.Length < 3)\n    return Color.Default;\nColor c = Color.Parse (userInput);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace (text) || text.Length < 3)\n    return Color.Default;\nColor c = Color.Parse (text);","typeGuard":"static bool IsPlausibleColorString (string s) => !string.IsNullOrWhiteSpace (s) && s.Length >= 3;","tryCatchPattern":"try { return Color.Parse (text); }\ncatch (ColorParseException) { return Color.Default; }","preventionTips":["Validate length >= 3 and non-whitespace before calling Parse.","Use Color.TryParse if available to avoid exceptions for user input.","Constrain UI color fields to known formats via a regex."],"tags":["drawing","color","parsing","validation"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}