gohugoio/hugo · error
both limit and seq must be provided
Error message
both limit and seq must be provided
What it means
The `after` and `first` collection functions require both a numeric limit and a sequence; if either argument is literally nil, Hugo returns this error before attempting conversion or iteration. It distinguishes 'you passed nothing' from 'you passed something un-iterable', which produces different errors further down.
Source
Thrown at tpl/collections/collections.go:67
loc: loc,
sortComp: compare.New(loc, true),
dCache: dCache,
deps: deps,
}
}
// Namespace provides template functions for the "collections" namespace.
type Namespace struct {
loc *time.Location
sortComp *compare.Namespace
dCache *hmaps.Cache[dKey, []int]
deps *deps.Deps
}
// After returns all the items after the first n items in list l.
func (ns *Namespace) After(n any, l any) (any, error) {
if n == nil || l == nil {
return nil, errors.New("both limit and seq must be provided")
}
nv, err := cast.ToIntE(n)
if err != nil {
return nil, err
}
if nv < 0 {
return nil, errors.New("sequence bounds out of range [" + cast.ToString(nv) + ":]")
}
lv := reflect.ValueOf(l)
lv, isNil := hreflect.Indirect(lv)
if isNil {
return nil, errors.New("can't iterate over a nil value")
}
switch lv.Kind() {View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Provide a default for the limit: `{{ first (.Params.limit | default 5) .Pages }}`.
- Guard the sequence: `{{ with .Pages }}{{ first 5 . }}{{ end }}`.
- Verify the config/front-matter key the limit is read from actually exists and is spelled correctly.
Example fix
<!-- before -->
{{ range first .Params.limit .Pages }}...{{ end }}
<!-- after -->
{{ range first (.Params.limit | default 5) .Pages }}...{{ end }} Defensive patterns
Strategy: validation
Validate before calling
{{ $n := 5 }}
{{ if and (isset $.Params "items") $n }}
{{ range first $n .Params.items }}...{{ end }}
{{ end }} Prevention
- Always call `first`/`last`/`after` with both the limit and the sequence: `first 10 .Pages`
- Guard against nil sequences from optional params before ranging
- When wrapping these in a partial, validate both inputs with `errorf` early instead of forwarding possibly-nil values
When it happens
Trigger: `{{ first nil .Pages }}`, `{{ after $n $list }}` where `$n` or `$list` is an unset variable / missing param that evaluates to nil, e.g. `{{ first .Params.limit .Pages }}` when `limit` is absent from front matter or site config.
Common situations: Reading the limit from site/page params that don't exist (`.Site.Params.mainSections` era configs, missing `paginate`/`limit` keys), passing `.Pages` on a context where it's nil, or renamed config keys after a Hugo upgrade leaving the param lookup nil.
Related errors
- sequence must be provided
- can't iterate over a nil value
- nil is not a valid key to group by
- symdiff: failed to convert value: %w
- arguments to symdiff must be slices or arrays
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/6aa7ef8d592d2152.json.
Report an issue: GitHub ↗.