{"record":{"id":"5818857015ac6fb1","repo":"tui-cs/Terminal.Gui","slug":"failed-to-parse-color-from-s","errorCode":null,"errorMessage":"Failed to parse Color from {s}","messagePattern":"Failed to parse Color from (.+?)","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/FileServices/FileSystemColorProvider.cs","lineNumber":451,"sourceCode":"            return extColor;\n        }\n\n        return null;\n    }\n\n    private static Color StringToColor (string str)\n    {\n        if (!Color.TryParse (str, out Color? c))\n        {\n            ThrowFormatException (str);\n        }\n\n        return c.Value;\n\n        [DoesNotReturn]\n        static void ThrowFormatException (string s)\n        {\n            throw new FormatException ($\"Failed to parse Color from {s}\");\n        }\n    }\n}\n","sourceCodeStart":433,"sourceCodeEnd":455,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/FileServices/FileSystemColorProvider.cs#L433-L455","documentation":"This error is thrown by FileSystemColorProvider.StringToColor() when Color.TryParse fails to parse a string into a Color value. The FileSystemColorProvider maps file names and extensions to colors for display in file dialogs. If a color string in the configuration (FilenameToColor or ExtensionToColor dictionaries) is not a valid color representation, a FormatException is thrown with the offending string.","triggerScenarios":"Thrown at FileSystemColorProvider.cs:451 (inside ThrowFormatException, called from StringToColor at line 443) when Color.TryParse(str, out Color? c) returns false. StringToColor is used internally when populating the FilenameToColor and ExtensionToColor dictionaries. The trigger is an invalid color string being added via configuration or code.","commonSituations":"A typo in a color configuration string (e.g., 'bluw' instead of 'blue'), using a color name not recognized by the Color parser (e.g., a CSS color name not in Terminal.Gui's color set), providing an invalid hex format (e.g., '#GGGGGG'), or loading a config file with corrupt color values.","solutions":["Verify the color string against Terminal.Gui's supported color names (e.g., 'red', 'blue', 'green') and valid hex formats ('#RRGGBB').","Use Color.TryParse yourself before adding to the dictionary to get a clear failure point.","Check the config file or code that populates FileSystemColorProvider for typos.","Correct the invalid color string to a valid color name or hex value."],"exampleFix":"// before -- invalid color string causes FormatException\nprovider.FilenameToColor[\"file.txt\"] = FileSystemColorProvider.StringToColor(\"bluw\");\n\n// after -- validate before use\nif (Color.TryParse(\"blue\", out Color? c)) { provider.FilenameToColor[\"file.txt\"] = c.Value; }","handlingStrategy":"validation","validationCode":"string colorStr = \"blue\";\nif (Color.TryParse(colorStr, out Color? c)) { provider.FilenameToColor[\"file.txt\"] = c.Value; }\nelse { Console.Error.WriteLine($\"Invalid color: {colorStr}\"); }","typeGuard":null,"tryCatchPattern":"try { Color color = StringToColor(colorStr); }\ncatch (FormatException ex) { Console.Error.WriteLine($\"Bad color config: {ex.Message}\"); /* use default color */ }","preventionTips":["Validate color strings with Color.TryParse before adding to FileSystemColorProvider dictionaries.","Check color configuration files for typos and invalid color names.","Use only Terminal.Gui-recognized color names and hex formats (#RRGGBB).","Add a config validation step at application startup."],"tags":["color","parsing","filesystem","configuration","filedialogs"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}