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
- Reduce the range so the result has ≤ 1,000,000 elements, e.g. clamp with `math.Min`.
- Check whether the bound variable holds what you expect (`printf "%d"`) — a timestamp or ID often sneaks in.
- 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
- Keep seq ranges small — it's meant for pagination-scale loops, not large numeric ranges.
- Compute the element count ((last-first)/step + 1) before calling seq when arguments are dynamic.
- For iterating over content, range the page collection directly instead of generating index sequences.
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
- invalid number of arguments to Seq
- 'increment' must not be 0
- the number of requested values (%v) must be a non-negative i
- error building site: %w
- failed to detect format from content
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/6cd6b350bfd5c05a.json.
Report an issue: GitHub ↗.