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

  1. Ensure every element of the slice passed to pagination is a PageGroup.
  2. Separate stray Page objects into their own slice or wrap them in a PageGroup with the Group method.
  3. 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

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


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)