{"record":{"id":"395af724ce0ccb4a","repo":"spectreconsole/spectre.console","slug":"color-number-has-null-name","errorCode":null,"errorMessage":"Color {number} has null name","messagePattern":"Color (.+?) has null name","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console.SourceGenerator/Colors/ColorModel.cs","lineNumber":36,"sourceCode":"/// <summary>\n/// Parses color data from JSON.\n/// </summary>\ninternal static class ColorParser\n{\n    /// <summary>\n    /// Parses the colors.json file and returns all color models.\n    /// </summary>\n    public static EquatableArray<ColorModel> ParseAll(string json)\n    {\n        var document = JsonDocument.Parse(json);\n        var colors = new List<ColorModel>();\n        var nameCounts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);\n\n        foreach (var element in document.RootElement.EnumerateArray())\n        {\n            var number = element.GetProperty(\"number\").GetInt32();\n            var name = element.GetProperty(\"name\").GetString()\n                ?? throw new InvalidOperationException($\"Color {number} has null name\");\n            var rgb = element.GetProperty(\"rgb\");\n            var r = (byte)rgb.GetProperty(\"r\").GetInt32();\n            var g = (byte)rgb.GetProperty(\"g\").GetInt32();\n            var b = (byte)rgb.GetProperty(\"b\").GetInt32();\n\n            // Track name occurrences for deduplication\n            var uniqueName = GetUniqueName(name, nameCounts);\n            colors.Add(new ColorModel(number, uniqueName, r, g, b, IsAlias: false));\n\n            // Process aliases\n            if (element.TryGetProperty(\"aliases\", out var aliases))\n            {\n                foreach (var alias in aliases.EnumerateArray())\n                {\n                    var aliasName = alias.GetString()\n                        ?? throw new InvalidOperationException($\"Color {number} has null alias\");\n                    var uniqueAliasName = GetUniqueName(aliasName, nameCounts);\n                    colors.Add(new ColorModel(number, uniqueAliasName, r, g, b, IsAlias: true));","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console.SourceGenerator/Colors/ColorModel.cs#L18-L54","documentation":"Thrown by ColorModel.ParseAll while reading colors.json: the JSON entry had a number property, but the name property parsed to a null string (the JSON token was null or GetString() returned null). Every color must have a non-null name, so this is treated as malformed data.","triggerScenarios":"A colors.json array element contains \"name\": null or omits a usable string value for name while having a valid number.","commonSituations":"Hand-editing colors.json and leaving a null name; a downstream fork of the color data with a typo; schema drift between the generator and the data file.","solutions":["Open the bundled colors.json and find the entry whose number matches the message; give it a real name string","Do not hand-edit the shipped colors.json; restore it from the Spectre.Console package","Validate the JSON against the expected schema before replacing the file"],"exampleFix":"// before\n{ \"number\": 14, \"name\": null, \"rgb\": {\"r\":0,\"g\":255,\"b\":255} }\n// after\n{ \"number\": 14, \"name\": \"cyan3\", \"rgb\": {\"r\":0,\"g\":255,\"b\":255} }","handlingStrategy":"validation","validationCode":"// Script to scan colors.json for null names before replacing it\nusing var doc = JsonDocument.Parse(File.ReadAllText(\"colors.json\"));\nforeach (var e in doc.RootElement.EnumerateArray())\n{\n    if (e.GetProperty(\"name\").ValueKind == JsonValueKind.Null)\n        Console.Error.WriteLine($\"color {e.GetProperty(\"number\").GetInt32()} has null name\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate edited colors.json against the expected schema before shipping","Do not fork the bundled data; restore from the package if unsure"],"tags":["json","source-generator","data-integrity","colors"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}