{"record":{"id":"b14e852efa3289ce","repo":"gohugoio/hugo","slug":"unsupported-type-in-paginate-from-slice-got-t-in","errorCode":null,"errorMessage":"unsupported type in paginate from slice, got %T instead of PageGroup","messagePattern":"unsupported type in paginate from slice, got %T instead of PageGroup","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pagegroup.go","lineNumber":453,"sourceCode":"\tcase nil:\n\t\treturn nil, true, nil\n\tcase PagesGroup:\n\t\treturn v, true, nil\n\tcase []PageGroup:\n\t\treturn PagesGroup(v), true, nil\n\tcase []any:\n\t\tl := len(v)\n\t\tif l == 0 {\n\t\t\tbreak\n\t\t}\n\t\tswitch v[0].(type) {\n\t\tcase PageGroup:\n\t\t\tpagesGroup := make(PagesGroup, l)\n\t\t\tfor i, ipg := range v {\n\t\t\t\tif pg, ok := ipg.(PageGroup); ok {\n\t\t\t\t\tpagesGroup[i] = pg\n\t\t\t\t} else {\n\t\t\t\t\treturn nil, false, fmt.Errorf(\"unsupported type in paginate from slice, got %T instead of PageGroup\", ipg)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn pagesGroup, true, nil\n\t\t}\n\t}\n\n\treturn nil, false, nil\n}\n","sourceCodeStart":435,"sourceCodeEnd":462,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/page/pagegroup.go#L435-L462","documentation":"Thrown by ToPagesGroup when converting a value for pagination. It inspects a []any whose first element is a PageGroup, then asserts every subsequent element is also a PageGroup; the first non-PageGroup element produces this error naming the offending type. It guards pagination against heterogeneous page-group slices.","triggerScenarios":"Calling the paginator on a []any slice whose first entry is a PageGroup but a later entry is a Page, a string, or any other type. For example, a content adapter or template assembles a mixed list and feeds it to .Paginator.","commonSituations":"A template concatenates grouped pages with stray page objects or metadata before paginating. Also surfaces when upgrading pagination code that previously handled plain Pages but now receives grouped data.","solutions":["Ensure every element of the slice passed to pagination is a PageGroup.","Separate stray Page objects into their own slice or wrap them in a PageGroup with the Group method.","Use ToPages (for flat Pages) or ToPagesGroup (for groups) consistently rather than mixing the two."],"exampleFix":"// before\nitems := []any{pg1, somePage, pg2}\ng, _, err := page.ToPagesGroup(items)\n// after\nitems := []any{pg1, page.PageGroup{Key: \"x\", Pages: page.Pages{somePage}}, pg2}","handlingStrategy":"validation","validationCode":"ok := true\nif s, isSlice := seq.([]any); isSlice && len(s) > 0 {\n    if _, firstIsPG := s[0].(page.PageGroup); firstIsPG {\n        for _, e := range s {\n            if _, ok2 := e.(page.PageGroup); !ok2 { ok = false; break }\n        }\n    }\n}\nif !ok { return errors.New(\"mixed slice\") }","typeGuard":"func allPageGroups(seq any) bool {\n    s, ok := seq.([]any)\n    if !ok || len(s) == 0 { return true }\n    if _, ok := s[0].(page.PageGroup); !ok { return false }\n    for _, e := range s {\n        if _, ok := e.(page.PageGroup); !ok { return false }\n    }\n    return true\n}","tryCatchPattern":"g, isGroup, err := page.ToPagesGroup(seq)\nif err != nil { /* log and fall back to ToPages */ }","preventionTips":["Never mix PageGroup with non-PageGroup elements in a slice you paginate.","Validate the slice homogeneity before passing to pagination.","Use ToPages for flat lists and ToPagesGroup for grouped lists consistently."],"tags":["hugo","pagination","page-group","type-mismatch"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}