{"record":{"id":"4218045ddf95800b","repo":"d2lang/d2","slug":"expected-fill-to-be-a-valid-named-color-orange","errorCode":null,"errorMessage":"expected \"fill\" to be a valid named color (\"orange\"), a hex code (\"#f0ff3a\"), or a gradient (\"linear-gradient(red, blue)\")","messagePattern":"expected \"fill\" to be a valid named color \\(\"orange\"\\), a hex code \\(\"#f0ff3a\"\\), or a gradient \\(\"linear-gradient\\(red, blue\\)\"\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2graph/d2graph.go","lineNumber":339,"sourceCode":"\t\tf, err := strconv.ParseFloat(value, 64)\n\t\tif err != nil || math.IsNaN(f) || math.IsInf(f, 0) || f < 0 || f > 1 {\n\t\t\treturn errors.New(`expected \"opacity\" to be a number between 0.0 and 1.0`)\n\t\t}\n\t\ts.Opacity.Value = value\n\tcase \"stroke\":\n\t\tif s.Stroke == nil {\n\t\t\tbreak\n\t\t}\n\t\tif !color.ValidColor(value) {\n\t\t\treturn errors.New(`expected \"stroke\" to be a valid named color (\"orange\"), a hex code (\"#f0ff3a\"), or a gradient (\"linear-gradient(red, blue)\")`)\n\t\t}\n\t\ts.Stroke.Value = value\n\tcase \"fill\":\n\t\tif s.Fill == nil {\n\t\t\tbreak\n\t\t}\n\t\tif !color.ValidColor(value) {\n\t\t\treturn errors.New(`expected \"fill\" to be a valid named color (\"orange\"), a hex code (\"#f0ff3a\"), or a gradient (\"linear-gradient(red, blue)\")`)\n\t\t}\n\t\ts.Fill.Value = value\n\tcase \"fill-pattern\":\n\t\tif s.FillPattern == nil {\n\t\t\tbreak\n\t\t}\n\t\tif !go2.Contains(d2ast.FillPatterns, strings.ToLower(value)) {\n\t\t\treturn fmt.Errorf(`expected \"fill-pattern\" to be one of: %s`, strings.Join(d2ast.FillPatterns, \", \"))\n\t\t}\n\t\ts.FillPattern.Value = value\n\tcase \"stroke-width\":\n\t\tif s.StrokeWidth == nil {\n\t\t\tbreak\n\t\t}\n\t\tf, err := strconv.Atoi(value)\n\t\tif err != nil || (f < 0 || f > 15) {\n\t\t\treturn errors.New(`expected \"stroke-width\" to be a number between 0 and 15`)\n\t\t}","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2graph/d2graph.go#L321-L357","documentation":"The 'fill' style key must pass color.ValidColor — a named color, hex code, or gradient. This error is returned when the fill value is invalid. Same validation pattern as stroke, applied to the shape's background fill.","triggerScenarios":"Setting style 'fill' to a non-color value, e.g. `fill: transparent-red`, `fill: #12345` (bad hex), or an unsupported function form.","commonSituations":"Copy-pasting CSS colors that D2 doesn't parse, typos in named colors, gradients written with unsupported syntax.","solutions":["Use a named color, hex code like \"#f0ff3a\", or \"linear-gradient(color1, color2)\".","Validate with color.ValidColor before assigning s.Fill.Value.","Correct hex length/characters and color name spelling."],"exampleFix":"// before\nx.style.fill: #12345\n// after\nx.style.fill: #112233","handlingStrategy":"validation","validationCode":"if !color.ValidColor(v) {\n    return fmt.Errorf(\"fill %q is not a named color, hex code, or gradient\", v)\n}","typeGuard":"func validFill(v string) bool { return color.ValidColor(v) }","tryCatchPattern":"if err := applyStyle(\"fill\", value); err != nil {\n    if strings.Contains(err.Error(), \"fill\") {\n        value = \"transparent\" // or a known-good default\n    }\n}","preventionTips":["Sanity-check hex codes for '#' prefix and correct digit count.","Run color.ValidColor on user-supplied fill values before applying.","Keep gradients in the linear-gradient(color1, color2) form."],"tags":["validation","d2graph","color","style"],"backgroundTag":"invalid-color-value","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}