gohugoio/hugo · error

too many padding values: received %d, expected maximum of 4

Error message

too many padding values: received %d, expected maximum of 4

What it means

Thrown by images.Padding when, after optionally consuming the trailing color, more than four numeric padding values remain (filters.go:187-189). The CSS shorthand supports at most top/right/bottom/left, so five numeric values are invalid.

Source

Thrown at resources/images/filters.go:188

	for _, v := range args {
		vi := cast.ToInt(v)
		if vi > 5000 {
			panic("padding values must not exceed 5000 pixels")
		}
		vals = append(vals, vi)
	}

	switch len(args) {
	case 1:
		top, right, bottom, left = vals[0], vals[0], vals[0], vals[0]
	case 2:
		top, right, bottom, left = vals[0], vals[1], vals[0], vals[1]
	case 3:
		top, right, bottom, left = vals[0], vals[1], vals[2], vals[1]
	case 4:
		top, right, bottom, left = vals[0], vals[1], vals[2], vals[3]
	default:
		panic(fmt.Sprintf("too many padding values: received %d, expected maximum of 4", len(args)))
	}

	return filter{
		Options: newFilterOpts(_args...),
		Filter: paddingFilter{
			top:    top,
			right:  right,
			bottom: bottom,
			left:   left,
			ccolor: ccolor,
		},
	}
}

// Dither creates a filter that dithers an image.
func (*Filters) Dither(options ...any) gift.Filter {
	ditherOptions := struct {
		Colors     []any

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Limit padding values to at most four (top, right, bottom, left).
  2. Use CSS shorthand: one value (all sides), two (vertical/horizontal), three (top/horizontal/bottom), or four (per side).
  3. Validate the length of computed arg slices before passing them.

Example fix

// before
{{ $filters = $filters | append (images.Padding 1 2 3 4 5) }}
// after
{{ $filters = $filters | append (images.Padding 1 2 3 4) }}
Defensive patterns

Strategy: validation

Validate before calling

{{ if gt (len $numericArgs) 4 }}{{ errorf "too many padding values: %d" (len $numericArgs) }}{{ end }}

Prevention

When it happens

Trigger: Effectively a defensive guard: the outer signature already caps total args at five, so reaching the default case requires five numeric values with none parsed as color. Triggered by passing five non-color arguments.

Common situations: Passing five pixel values, or a dynamically built slice that expands to five numbers.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/87b4b998895216c7. Report an issue: GitHub.