{"record":{"id":"1666b46d12f8f453","repo":"gohugoio/hugo","slug":"invalid-canvas-color-specify-rgb-or-rgba-using-he","errorCode":null,"errorMessage":"invalid canvas color: specify RGB or RGBA using hex notation","messagePattern":"invalid canvas color: specify RGB or RGBA using hex notation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/filters.go","lineNumber":160,"sourceCode":"// Padding creates a filter that resizes the image canvas without resizing the\n// image. The last argument is the canvas color, expressed as an RGB or RGBA\n// hexadecimal color. The default value is `ffffffff` (opaque white). The\n// preceding arguments are the padding values, in pixels, using the CSS\n// shorthand property syntax. Negative padding values will crop the image. The\n// signature is images.Padding V1 [V2] [V3] [V4] [COLOR].\nfunc (*Filters) Padding(args ...any) gift.Filter {\n\tif len(args) < 1 || len(args) > 5 {\n\t\tpanic(\"the padding filter requires between 1 and 5 arguments\")\n\t}\n\n\tvar top, right, bottom, left int\n\tvar ccolor color.Color = color.White // canvas color\n\n\t_args := args // preserve original args for most stable hash\n\n\tif vcs, ok, err := toColorGo(args[len(args)-1]); ok || err != nil {\n\t\tif err != nil {\n\t\t\tpanic(\"invalid canvas color: specify RGB or RGBA using hex notation\")\n\t\t}\n\t\tccolor = vcs\n\t\targs = args[:len(args)-1]\n\t\tif len(args) == 0 {\n\t\t\tpanic(\"not enough arguments: provide one or more padding values using the CSS shorthand property syntax\")\n\t\t}\n\t}\n\n\tvar vals []int\n\tfor _, v := range args {\n\t\tvi := cast.ToInt(v)\n\t\tif vi > 5000 {\n\t\t\tpanic(\"padding values must not exceed 5000 pixels\")\n\t\t}\n\t\tvals = append(vals, vi)\n\t}\n\n\tswitch len(args) {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/images/filters.go#L142-L178","documentation":"Thrown by images.Padding when the trailing argument is parsed as a color and parsing returns a hard error (filters.go:158-161) — i.e. the value looked color-like enough to attempt parsing but was malformed. Valid formats are RGB/RGBA hex (3, 4, 6, or 8 hex digits, optional leading #).","triggerScenarios":"Passing a canvas color like \"#GGG\", \"12345\", \"ff0000ff00\", or a non-hex string in the trailing slot. Note: a value that cannot be stringified returns ok=false (no panic); only an actual parse error triggers this.","commonSituations":"Typos in hex color, copying colors with alpha in the wrong position, using named CSS colors (\"red\") which the parser does not accept, or trailing whitespace/newline in the color string.","solutions":["Use a valid hex color: RRGGBB or RRGGBBAA (or shorthand RGB/RGBA), optionally prefixed with #.","Strip whitespace from dynamically generated color strings.","Avoid named CSS colors; convert them to hex first."],"exampleFix":"// before\n{{ $filters = $filters | append (images.Padding 10 \"#ZZZ\") }}\n// after\n{{ $filters = $filters | append (images.Padding 10 \"0000ffff\") }}","handlingStrategy":"validation","validationCode":"{{ $color := .color | default \"ffffff\" }}\n{{ if not (findRE `^[0-9a-fA-F]{3,4}$|^[0-9a-fA-F]{6}$|^[0-9a-fA-F]{8}$` (trimPrefix \"#\" $color)) }}\n  {{ errorf \"invalid canvas color %q\" $color }}\n{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate hex color format (3/4/6/8 hex digits) before passing.","Strip a leading # consistently.","Avoid named CSS colors."],"tags":["image-filter","padding","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"}