{"record":{"id":"ef40cfbfbb3a8ad1","repo":"gohugoio/hugo","slug":"both-count-and-seq-must-be-provided","errorCode":null,"errorMessage":"both count and seq must be provided","messagePattern":"both count and seq must be provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/collections.go","lineNumber":498,"sourceCode":"\t}\n\n\tseq := make([]int, size)\n\tval := first\n\tfor i := 0; ; i++ {\n\t\tseq[i] = val\n\t\tval += inc\n\t\tif (inc < 0 && val < last) || (inc > 0 && val > last) {\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn seq, nil\n}\n\n// Shuffle returns list l in a randomized order.\nfunc (ns *Namespace) Shuffle(l any) (any, error) {\n\tif l == nil {\n\t\treturn nil, errors.New(\"both count and seq must be provided\")\n\t}\n\n\tlv := reflect.ValueOf(l)\n\tlv, isNil := hreflect.Indirect(lv)\n\tif isNil {\n\t\treturn nil, errors.New(\"can't iterate over a nil value\")\n\t}\n\n\tswitch lv.Kind() {\n\tcase reflect.Array, reflect.Slice, reflect.String:\n\t\t// okay\n\tdefault:\n\t\treturn nil, errors.New(\"can't iterate over \" + reflect.ValueOf(l).Type().String())\n\t}\n\n\tshuffled := reflect.MakeSlice(reflect.TypeOf(l), lv.Len(), lv.Len())\n\n\trandomIndices := rand.Perm(lv.Len())","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/collections.go#L480-L516","documentation":"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.","triggerScenarios":"Calling {{ shuffle .Pages }} when .Pages is nil (empty section); piping a nil scratch value or failed lookup into shuffle; passing an unset variable.","commonSituations":"Empty taxonomies/sections; optional partial parameters defaulting to nil; lookups (index, .Param) returning nil fed straight into shuffle.","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."],"exampleFix":"// before\n{{ shuffle .Pages }}\n// after\n{{ with .Pages }}{{ shuffle . }}{{ end }}","handlingStrategy":"validation","validationCode":"{{ with .Pages }}{{ shuffle . }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["hugo","template","collections","shuffle","nil-check","argument-validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}