gohugoio/hugo · error

Paginator size must be positive

Error message

Paginator size must be positive

What it means

Defensive guard in newPaginatorFromPages (and its PageGroups sibling) rejecting a non-positive page size when constructing the paginator. It is the lower-level counterpart to error 315 — the size reaching the paginator constructor must be positive.

Source

Thrown at resources/page/pagination.go:360

	// probably the same wrong type
	if err1 != nil && err2 != nil {
		return true
	}

	if len(p1) != len(p2) {
		return false
	}

	if len(p1) == 0 {
		return true
	}

	return p1[0] == p2[0]
}

func newPaginatorFromPages(pages Pages, size int, urlFactory paginationURLFactory) (*Paginator, error) {
	if size <= 0 {
		return nil, errors.New("Paginator size must be positive")
	}

	split := splitPages(pages, size)

	return newPaginator(split, len(pages), size, urlFactory)
}

func newPaginatorFromPageGroups(pageGroups PagesGroup, size int, urlFactory paginationURLFactory) (*Paginator, error) {
	if size <= 0 {
		return nil, errors.New("Paginator size must be positive")
	}

	split := splitPageGroups(pageGroups, size)

	return newPaginator(split, pageGroups.Len(), size, urlFactory)
}

func newPaginator(elements []paginatedElement, total, size int, urlFactory paginationURLFactory) (*Paginator, error) {

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Ensure the pager size passed to .Paginate is a positive integer
  2. Fix `pagination.pagerSize` in site config to a value >= 1
  3. If computing the size in templates, guard against zero before calling .Paginate

Example fix

// before
{{ $size := sub $n $n }}{{ $pag := .Paginate .Pages $size }}
// after
{{ $size := default 10 $computed }}{{ $pag := .Paginate .Pages $size }}
Defensive patterns

Strategy: validation

Validate before calling

{{ $size := 12 }}{{ if gt $size 0 }}{{ $pag := .Paginate .Pages $size }}{{ end }}

Prevention

When it happens

Trigger: Internal construction of a Paginator with size <= 0; in practice reached when a zero/negative pager size slips past higher-level checks, e.g. via internal callers of newPaginatorFromPages or unusual argument coercion.

Common situations: Same root causes as the config check: `pagination.pagerSize` set to 0/negative, or a template passing a computed size that evaluates to 0 (e.g. `{{ .Paginate .Pages (sub 1 1) }}`).

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/073e8de800950be7.json. Report an issue: GitHub ↗.