{"id":"6aa7ef8d592d2152","repo":"gohugoio/hugo","slug":"both-limit-and-seq-must-be-provided","errorCode":null,"errorMessage":"both limit and seq must be provided","messagePattern":"both limit and seq must be provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/collections.go","lineNumber":67,"sourceCode":"\t\tloc:      loc,\n\t\tsortComp: compare.New(loc, true),\n\t\tdCache:   dCache,\n\t\tdeps:     deps,\n\t}\n}\n\n// Namespace provides template functions for the \"collections\" namespace.\ntype Namespace struct {\n\tloc      *time.Location\n\tsortComp *compare.Namespace\n\tdCache   *hmaps.Cache[dKey, []int]\n\tdeps     *deps.Deps\n}\n\n// After returns all the items after the first n items in list l.\nfunc (ns *Namespace) After(n any, l any) (any, error) {\n\tif n == nil || l == nil {\n\t\treturn nil, errors.New(\"both limit and seq must be provided\")\n\t}\n\n\tnv, err := cast.ToIntE(n)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif nv < 0 {\n\t\treturn nil, errors.New(\"sequence bounds out of range [\" + cast.ToString(nv) + \":]\")\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() {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/collections.go#L49-L85","documentation":"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.","triggerScenarios":"`{{ 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.","commonSituations":"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.","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."],"exampleFix":"<!-- before -->\n{{ range first .Params.limit .Pages }}...{{ end }}\n<!-- after -->\n{{ range first (.Params.limit | default 5) .Pages }}...{{ end }}","handlingStrategy":"validation","validationCode":"{{ $n := 5 }}\n{{ if and (isset $.Params \"items\") $n }}\n  {{ range first $n .Params.items }}...{{ end }}\n{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["hugo","templates","collections","nil","first-after"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}