{"record":{"id":"9d5889eb2b0b1892","repo":"gohugoio/hugo","slug":"the-padding-filter-requires-between-1-and-5-argume","errorCode":null,"errorMessage":"the padding filter requires between 1 and 5 arguments","messagePattern":"the padding filter requires between 1 and 5 arguments","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/filters.go","lineNumber":150,"sourceCode":"\t\t\t}\n\t\t}\n\t}\n\n\treturn filter{\n\t\tOptions: newFilterOpts(text, opt),\n\t\tFilter:  tf,\n\t}\n}\n\n// 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","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/images/filters.go#L132-L168","documentation":"Thrown by images.Padding when the variadic argument count is outside 1..5 (filters.go:149-151). Padding accepts 1-4 pixel values plus an optional trailing canvas color, so zero or more than five arguments are rejected up front.","triggerScenarios":"Calling images.Padding with no arguments, or with six or more arguments. Also triggered by accidentally passing a slice that expands into too many values.","commonSituations":"Template logic conditionally builds the arg list and ends up empty; developer misunderstands the signature as Padding(color) only; or passes both individual values and a map.","solutions":["Provide between 1 and 5 arguments following the signature Padding V1 [V2] [V3] [V4] [COLOR].","If the color is omitted, ensure 1-4 pixel values are present.","Guard dynamic arg lists so they never collapse to zero or exceed five."],"exampleFix":"// before\n{{ $filters = $filters | append (images.Padding) }}\n// after\n{{ $filters = $filters | append (images.Padding 20) }}","handlingStrategy":"validation","validationCode":"{{ $args := slice }}\n{{ range $v := .paddings }}{{ $args = $args | append $v }}{{ end }}\n{{ if lt (len $args) 1 }}{{ errorf \"Padding needs 1-5 args\" }}{{ end }}\n{{ if gt (len $args) 5 }}{{ errorf \"Padding needs 1-5 args\" }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bound dynamically built arg lists to the 1-5 range before calling Padding.","Remember the optional color occupies one of the five slots.","Prefer fixed-arity calls when possible."],"tags":["image-filter","padding","validation","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}