gohugoio/hugo · error

size of result exceeds limit

Error message

size of result exceeds limit

What it means

Thrown by the Seq function (and D) via the shared errSeqSizeExceedsLimit sentinel (line 417) when the requested sequence would exceed maxSeqSize (1,000,000). Trips on two conditions: when 'last' < -1,000,000, or when the computed size ((last-first)/inc + 1) is <=0 or > 1,000,000. This is a resource guard against unbounded slice allocation.

Source

Thrown at tpl/collections/collections.go:417

	case reflect.Slice:
	default:
		return nil, errors.New("argument must be a slice")
	}

	sliceCopy := reflect.MakeSlice(v.Type(), v.Len(), v.Len())

	for i := v.Len() - 1; i >= 0; i-- {
		element := sliceCopy.Index(i)
		element.Set(v.Index(v.Len() - 1 - i))
	}

	return sliceCopy.Interface(), nil
}

// Sanity check for slices created by Seq and D.
const maxSeqSize = 1000000

var errSeqSizeExceedsLimit = errors.New("size of result exceeds limit")

// Seq creates a sequence of integers from args. It's named and used as GNU's seq.
//
// Examples:
//
//	3 => 1, 2, 3
//	1 2 4 => 1, 3
//	-3 => -1, -2, -3
//	1 4 => 1, 2, 3, 4
//	1 -2 => 1, 0, -1, -2
func (ns *Namespace) Seq(args ...any) ([]int, error) {
	if len(args) < 1 || len(args) > 3 {
		return nil, errors.New("invalid number of arguments to Seq")
	}

	intArgs := cast.ToIntSlice(args)
	if len(intArgs) < 1 || len(intArgs) > 3 {
		return nil, errors.New("invalid arguments to Seq")

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Reduce the range: cap 'last' so (last-first)/inc+1 stays under 1,000,000.
  2. Switch to a Go-backed shortcode or partial that streams the range instead of materializing it in the template.
  3. Sanitize inputs: clamp the end value with math.Min before passing to seq.

Example fix

// before
{{ seq 1 1 9999999 }}
// after
{{ $end := math.Min 999999 $computedEnd }}
{{ seq 1 1 $end }}
Defensive patterns

Strategy: validation

Validate before calling

{{ $end := math.Min 999999 $computedEnd }}
{{ seq 1 1 $end }}

Prevention

When it happens

Trigger: Calling {{ seq 1 1 9999999 }} (increment 1, end ~10M -> size ~10M > 1M); {{ seq 1 0 5000000 }}; passing front matter-derived large bounds; a negative increment producing an oversized backward range. Also when the size computation overflows logically to <=0.

Common situations: Looping over large data sets with seq in a template; computed bounds from pagination/counts going unexpectedly large; accidentally passing a byte count or ID as a seq end.

Related errors


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