{"record":{"id":"232a2dd3f45f04bc","repo":"gohugoio/hugo","slug":"invalid-color-code-q","errorCode":null,"errorMessage":"invalid color code: %q","messagePattern":"invalid color code: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/color.go","lineNumber":166,"sourceCode":"\t\treturn vv.ColorGo(), true, nil\n\tdefault:\n\t\ts, ok := hstrings.ToString(v)\n\t\tif !ok {\n\t\t\treturn nil, false, nil\n\t\t}\n\t\tc, err := hexStringToColorGo(s)\n\t\tif err != nil {\n\t\t\treturn nil, false, err\n\t\t}\n\t\treturn c, true, nil\n\t}\n}\n\nfunc hexStringToColorGo(s string) (color.Color, error) {\n\ts = strings.TrimPrefix(s, \"#\")\n\n\tif len(s) != 3 && len(s) != 4 && len(s) != 6 && len(s) != 8 {\n\t\treturn nil, fmt.Errorf(\"invalid color code: %q\", s)\n\t}\n\n\ts = strings.ToLower(s)\n\n\tif len(s) == 3 || len(s) == 4 {\n\t\tvar v strings.Builder\n\t\tfor _, r := range s {\n\t\t\tv.WriteString(string(r) + string(r))\n\t\t}\n\t\ts = v.String()\n\t}\n\n\t// Standard colors.\n\tif s == \"ffffff\" {\n\t\treturn color.White, nil\n\t}\n\n\tif s == \"000000\" {","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/images/color.go#L148-L184","documentation":"Returned by hexStringToColorGo when the input string (after stripping '#') has a length other than 3, 4, 6, or 8 characters. Valid hex colors are RGB (3), RGBA (4), RRGGBB (6), or RRGGBBAA (8); any other length is rejected before attempting hex.DecodeString.","triggerScenarios":"Passing a malformed color string to any color config (imaging.bgColor, a #bg option in an image spec, or a color Param). E.g. \"#ff\" (2 chars), \"#fffff\" (5), \"#12345\" (5), or a non-hex length like \"white\".","commonSituations":"A typo in imaging.bgColor in hugo.toml (e.g. \"#fffff\" intended as ffffff), a template passing a named color instead of hex, a stray character dropping the length.","solutions":["Use a 3-, 6-, or 8-digit hex code (with optional leading #): #fff, #ffffff, #ffffffaa.","Do not pass CSS named colors (red, blue) -- only hex is accepted.","Count the hex digits after the #: must be 3, 4, 6, or 8."],"exampleFix":"// before\n[imaging]\nbgColor = \"#fffff\"\n\n// after\n[imaging]\nbgColor = \"#ffffff\"","handlingStrategy":"validation","validationCode":"var validHexLen = map[int]bool{3: true, 4: true, 6: true, 8: true}\nfunc isValidHexColor(s string) bool {\n    s = strings.TrimPrefix(s, \"#\")\n    if !validHexLen[len(s)] { return false }\n    _, err := hex.DecodeString(padShortHex(s))\n    return err == nil\n}","typeGuard":"func isValidHexColorCode(s string) bool {\n    s = strings.TrimPrefix(s, \"#\")\n    if len(s) != 3 && len(s) != 4 && len(s) != 6 && len(s) != 8 { return false }\n    for _, r := range s {\n        if !((r >= '0' && r <= '9') || (r >= 'a' && r <= 'f') || (r >= 'A' && r <= 'F')) { return false }\n    }\n    return true\n}","tryCatchPattern":null,"preventionTips":["Use 6-digit hex (#rrggbb) for clarity.","Never pass named CSS colors; only hex is accepted.","Validate color strings in config tests."],"tags":["image-processing","color","config","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}