gohugoio/hugo · error
both limit and seq must be provided
Error message
both limit and seq must be provided
What it means
After (collections.go:65-68) requires both a limit (n) and a sequence (l); if either is nil it stops immediately. Literal nil is the trigger here (typed-nil is caught later at line 82 with a different message).
Solutions
- Provide concrete non-nil values for both limit and list
- Guard: {{ with $list }}{{ after 5 . }}{{ end }}
- Default the limit: {{ after (default $n 5) $list }}
Example fix
// before
{{ after 5 $maybeNil }}
// after
{{ with $maybeNil }}{{ after 5 . }}{{ end }} Defensive patterns
Strategy: validation
Validate before calling
{{ with $list }}
{{ after (default $n 5) . }}
{{ end }} Prevention
- Provide concrete non-nil limit and list
- Remember the pipe target becomes the first positional arg, so mind order
- Default optional params with (default $v 5)
When it happens
Trigger: {{ after 5 nil }}, {{ after nil .Pages }}, or {{ nil | after 5 }} (note pipe makes nil the first positional arg = n).
Common situations: A frontmatter param used as limit that defaulted to nil; a missing page-collection variable passed as the list; reversed pipe argument order.
Related errors
- both count and seq must be provided
- can't find function
- can't iterate over a nil value
- can't iterate over a nil value
- cannot index slice/array with nil
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/6aa7ef8d592d2152.
Report an issue: GitHub.
Appendix: 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 52c9bd7908)