{"id":"14f8ead909124ec7","repo":"gohugoio/hugo","slug":"sequence-must-be-provided","errorCode":null,"errorMessage":"sequence must be provided","messagePattern":"sequence must be provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/sort.go","lineNumber":33,"sourceCode":"\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"reflect\"\n\t\"sort\"\n\t\"strings\"\n\n\t\"github.com/gohugoio/hugo/common/hmaps\"\n\t\"github.com/gohugoio/hugo/common/hreflect\"\n\t\"github.com/gohugoio/hugo/langs\"\n\t\"github.com/gohugoio/hugo/tpl/compare\"\n\t\"github.com/spf13/cast\"\n)\n\n// Sort returns a sorted copy of the list l.\nfunc (ns *Namespace) Sort(ctx context.Context, l any, args ...any) (any, error) {\n\tif l == nil {\n\t\treturn nil, errors.New(\"sequence must be provided\")\n\t}\n\n\tseqv, isNil := hreflect.Indirect(reflect.ValueOf(l))\n\tif isNil {\n\t\treturn nil, errors.New(\"can't iterate over a nil value\")\n\t}\n\n\tctxv := reflect.ValueOf(ctx)\n\n\tvar sliceType reflect.Type\n\tswitch seqv.Kind() {\n\tcase reflect.Array, reflect.Slice:\n\t\tsliceType = seqv.Type()\n\tcase reflect.Map:\n\t\tsliceType = reflect.SliceOf(seqv.Type().Elem())\n\tdefault:\n\t\treturn nil, errors.New(\"can't sort \" + reflect.ValueOf(l).Type().String())\n\t}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/sort.go#L15-L51","documentation":"Hugo's `sort` (collections.Sort) requires a collection as its first argument. In tpl/collections/sort.go the function immediately checks `l == nil` and returns this error, failing fast rather than sorting nothing. It means the value handed to `sort` was a literal untyped nil at the template level.","triggerScenarios":"`{{ sort .Params.missing }}` where the key doesn't exist, `{{ sort nil }}`, or `{{ sort (.Store.Get \"key\") }}` when the store entry was never set — any expression that evaluates to untyped nil passed as the sequence.","commonSituations":"Sorting a front-matter or site param that isn't defined on every page (e.g. `sort .Params.tags` on pages without tags); sorting the result of `where`/`index` lookups against missing keys; config keys renamed between Hugo versions leaving templates referencing nil params.","solutions":["Guard the call: `{{ with .Params.tags }}{{ sort . }}{{ end }}`.","Provide a default: `{{ sort (.Params.tags | default slice) }}`.","Verify the front-matter/config key actually exists and is spelled correctly on all pages that render the template."],"exampleFix":"<!-- before -->\n{{ range sort .Params.tags }}...{{ end }}\n<!-- after -->\n{{ range sort (.Params.tags | default slice) }}...{{ end }}","handlingStrategy":"validation","validationCode":"{{ $seq := .Params.items }}\n{{ if $seq }}{{ sort $seq }}{{ end }}","typeGuard":null,"tryCatchPattern":"{{ with try (sort $seq \"weight\") }}{{ if .Err }}{{ warnf \"sort failed: %s\" .Err }}{{ else }}{{ range .Value }}...{{ end }}{{ end }}{{ end }}","preventionTips":["Always call sort with an argument — never pipe a possibly-missing variable straight in","Wrap sorts of optional data in `{{ with $seq }}{{ sort . }}{{ end }}`","Provide the sequence positionally; don't rely on context that may be absent"],"tags":["hugo","templates","collections","sort","nil"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}