gohugoio/hugo · error
unsupported type in paginate from slice, got %T instead of…
Error message
unsupported type in paginate from slice, got %T instead of PageGroup
What it means
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.
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.
Example fix
// before
items := []any{pg1, somePage, pg2}
g, _, err := page.ToPagesGroup(items)
// after
items := []any{pg1, page.PageGroup{Key: "x", Pages: page.Pages{somePage}}, pg2} Defensive patterns
Strategy: validation
Validate before calling
ok := true
if s, isSlice := seq.([]any); isSlice && len(s) > 0 {
if _, firstIsPG := s[0].(page.PageGroup); firstIsPG {
for _, e := range s {
if _, ok2 := e.(page.PageGroup); !ok2 { ok = false; break }
}
}
}
if !ok { return errors.New("mixed slice") } Type guard
func allPageGroups(seq any) bool {
s, ok := seq.([]any)
if !ok || len(s) == 0 { return true }
if _, ok := s[0].(page.PageGroup); !ok { return false }
for _, e := range s {
if _, ok := e.(page.PageGroup); !ok { return false }
}
return true
} Try / catch
g, isGroup, err := page.ToPagesGroup(seq)
if err != nil { /* log and fall back to ToPages */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- invalid slice type %T
- argument must be a slice
- called apply using as type
- can't iterate over
- cannot convert type %T to Pages
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/b14e852efa3289ce.
Report an issue: GitHub.
Appendix: source
Thrown at resources/page/pagegroup.go:453
case nil:
return nil, true, nil
case PagesGroup:
return v, true, nil
case []PageGroup:
return PagesGroup(v), true, nil
case []any:
l := len(v)
if l == 0 {
break
}
switch v[0].(type) {
case PageGroup:
pagesGroup := make(PagesGroup, l)
for i, ipg := range v {
if pg, ok := ipg.(PageGroup); ok {
pagesGroup[i] = pg
} else {
return nil, false, fmt.Errorf("unsupported type in paginate from slice, got %T instead of PageGroup", ipg)
}
}
return pagesGroup, true, nil
}
}
return nil, false, nil
}
View on GitHub (pinned to 52c9bd7908)