gohugoio/hugo · error
both count and seq must be provided
Error message
both count and seq must be provided
What it means
Thrown by the Shuffle template function when its only argument (the list) is nil (line 497). The message text says 'both count and seq must be provided' but Shuffle takes a single list argument; this is a copy-paste message from the After/Last family. It fires before any reflection.
Source
Thrown at tpl/collections/collections.go:498
}
seq := make([]int, size)
val := first
for i := 0; ; i++ {
seq[i] = val
val += inc
if (inc < 0 && val < last) || (inc > 0 && val > last) {
break
}
}
return seq, nil
}
// Shuffle returns list l in a randomized order.
func (ns *Namespace) Shuffle(l any) (any, error) {
if l == nil {
return nil, errors.New("both count and seq must be provided")
}
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() {
case reflect.Array, reflect.Slice, reflect.String:
// okay
default:
return nil, errors.New("can't iterate over " + reflect.ValueOf(l).Type().String())
}
shuffled := reflect.MakeSlice(reflect.TypeOf(l), lv.Len(), lv.Len())
randomIndices := rand.Perm(lv.Len())View on GitHub (pinned to 52c9bd7908)
Solutions
- Coalesce to an empty slice: {{ $pages := .Pages | default slice }} {{ shuffle $pages }}.
- Guard with {{ with .Pages }}{{ shuffle . }}{{ end }} to skip shuffling an empty set.
- Ensure upstream providers return empty non-nil slices.
Example fix
// before
{{ shuffle .Pages }}
// after
{{ with .Pages }}{{ shuffle . }}{{ end }} Defensive patterns
Strategy: validation
Validate before calling
{{ with .Pages }}{{ shuffle . }}{{ end }} Prevention
- Coalesce the list with | default slice.
- Guard shuffle with {{ with }} for optional collections.
- Note the misleading message: shuffle takes one list arg, not count+seq.
When it happens
Trigger: Calling {{ shuffle .Pages }} when .Pages is nil (empty section); piping a nil scratch value or failed lookup into shuffle; passing an unset variable.
Common situations: Empty taxonomies/sections; optional partial parameters defaulting to nil; lookups (index, .Param) returning nil fed straight into shuffle.
Related errors
- cannot index slice/array with nil
- both limit and seq must be provided
- nil is not a valid key to group by
- invalid number of arguments to Seq
- invalid arguments to Seq
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/ef40cfbfbb3a8ad1.
Report an issue: GitHub.