{"record":{"id":"3f0ab9c0a7feb3ed","repo":"gohugoio/hugo","slug":"q-is-an-invalid-color-specify-rgb-or-rgba-using","errorCode":null,"errorMessage":"%q is an invalid color: specify RGB or RGBA using hexadecimal notation","messagePattern":"%q is an invalid color: specify RGB or RGBA using hexadecimal notation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/filters.go","lineNumber":235,"sourceCode":"\t\terr := mapstructure.WeakDecode(options[0], &ditherOptions)\n\t\tif err != nil {\n\t\t\tpanic(fmt.Sprintf(\"failed to decode options: %s\", err))\n\t\t}\n\t}\n\n\tif len(ditherOptions.Colors) == 0 {\n\t\tditherOptions.Colors = []any{\"000000ff\", \"ffffffff\"}\n\t}\n\n\tif len(ditherOptions.Colors) < 2 {\n\t\tpanic(\"palette must have at least two colors\")\n\t}\n\n\tvar palette []color.Color\n\tfor _, c := range ditherOptions.Colors {\n\t\tcc, ok, err := toColorGo(c)\n\t\tif !ok || err != nil {\n\t\t\tpanic(fmt.Sprintf(\"%q is an invalid color: specify RGB or RGBA using hexadecimal notation\", c))\n\t\t}\n\t\tpalette = append(palette, cc)\n\t}\n\n\td := dither.NewDitherer(palette)\n\tif method, ok := ditherMethodsErrorDiffusion[strings.ToLower(ditherOptions.Method)]; ok {\n\t\td.Matrix = dither.ErrorDiffusionStrength(method, ditherOptions.Strength)\n\t\td.Serpentine = ditherOptions.Serpentine\n\t} else if method, ok := ditherMethodsOrdered[strings.ToLower(ditherOptions.Method)]; ok {\n\t\td.Mapper = dither.PixelMapperFromMatrix(method, ditherOptions.Strength)\n\t} else {\n\t\tpanic(fmt.Sprintf(\"%q is an invalid dithering method: see documentation\", ditherOptions.Method))\n\t}\n\n\treturn filter{\n\t\tOptions: newFilterOpts(ditherOptions),\n\t\tFilter:  ditherFilter{ditherer: d},\n\t}","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/images/filters.go#L217-L253","documentation":"Thrown by images.Dither when a palette color fails to parse via toColorGo (filters.go:232-236) — either it is not convertible to a string or it is a malformed hex value. The offending value is printed (%q).","triggerScenarios":"Any palette entry that is not valid hex (3/4/6/8 hex digits, optional #). Passing a named color, a malformed hex, or a non-string non-colorGoProvider value triggers it.","commonSituations":"Using CSS named colors (\"red\"), truncated hex, or accidentally including a number/object in the Colors slice.","solutions":["Express every palette color as RGB/RGBA hex.","Filter out invalid entries before passing the slice.","Ensure each element is a string or an object implementing the colorGoProvider interface."],"exampleFix":"// before\n{{ $filters = $filters | append (images.Dither (dict \"Colors\" (slice \"red\" \"white\"))) }}\n// after\n{{ $filters = $filters | append (images.Dither (dict \"Colors\" (slice \"ff0000ff\" \"ffffffff\"))) }}","handlingStrategy":"validation","validationCode":"{{ range $c := $colors }}\n  {{ if not (findRE `^[0-9a-fA-F]{3,4}$|^[0-9a-fA-F]{6}$|^[0-9a-fA-F]{8}$` (trimPrefix \"#\" (printf \"%v\" $c))) }}\n    {{ errorf \"invalid palette color %q\" $c }}\n  {{ end }}\n{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only RGB/RGBA hex strings in palettes.","Convert named colors to hex upstream.","Sanitize the slice before passing."],"tags":["image-filter","dither","color","validation","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}