gohugoio/hugo · error

errSeqSizeExceedsLimit

errSeqSizeExceedsLimit

Error message

size of result exceeds limit

What it means

Hugo caps sequences produced by the `seq` (and `collections.D`) functions at `maxSeqSize` = 1,000,000 elements as a sanity check. If the computed size `((last-first)/inc)+1` exceeds that limit, is non-positive, or the bound is below -1,000,000, `errSeqSizeExceedsLimit` is returned to prevent runaway memory allocation during a build.

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 8a468df065)

Solutions

  1. Reduce the range so the result has ≤ 1,000,000 elements, e.g. clamp with `math.Min`.
  2. Check whether the bound variable holds what you expect (`printf "%d"`) — a timestamp or ID often sneaks in.
  3. Restructure the template to avoid materializing huge ranges; use pagination or `first`/`after` on real collections.

Example fix

<!-- before -->
{{ range seq $bigCount }}...{{ end }}
<!-- after -->
{{ range seq (math.Min $bigCount 1000) }}...{{ end }}
Defensive patterns

Strategy: validation

Validate before calling

{{/* seq result is capped (~2000 elements); check span first */}}
{{ $n := sub $last $first }}
{{ if gt $n 2000 }}
  {{ errorf "seq range too large: %d" $n }}
{{ else }}
  {{ range seq $first $last }}...{{ end }}
{{ end }}

Prevention

When it happens

Trigger: `{{ seq 2000000 }}`, `{{ seq 1 10000000 }}`, or any first/last/increment combination whose element count exceeds 1,000,000 (or underflows below -1,000,000).

Common situations: Using `seq` with a large computed value from `.Params` or site data (e.g. a timestamp or byte count mistakenly used as a count); generating paginated ranges from unbounded user data.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/6cd6b350bfd5c05a.json. Report an issue: GitHub ↗.