{"id":"073e8de800950be7","repo":"gohugoio/hugo","slug":"paginator-size-must-be-positive","errorCode":null,"errorMessage":"Paginator size must be positive","messagePattern":"Paginator size must be positive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pagination.go","lineNumber":360,"sourceCode":"\t// probably the same wrong type\n\tif err1 != nil && err2 != nil {\n\t\treturn true\n\t}\n\n\tif len(p1) != len(p2) {\n\t\treturn false\n\t}\n\n\tif len(p1) == 0 {\n\t\treturn true\n\t}\n\n\treturn p1[0] == p2[0]\n}\n\nfunc newPaginatorFromPages(pages Pages, size int, urlFactory paginationURLFactory) (*Paginator, error) {\n\tif size <= 0 {\n\t\treturn nil, errors.New(\"Paginator size must be positive\")\n\t}\n\n\tsplit := splitPages(pages, size)\n\n\treturn newPaginator(split, len(pages), size, urlFactory)\n}\n\nfunc newPaginatorFromPageGroups(pageGroups PagesGroup, size int, urlFactory paginationURLFactory) (*Paginator, error) {\n\tif size <= 0 {\n\t\treturn nil, errors.New(\"Paginator size must be positive\")\n\t}\n\n\tsplit := splitPageGroups(pageGroups, size)\n\n\treturn newPaginator(split, pageGroups.Len(), size, urlFactory)\n}\n\nfunc newPaginator(elements []paginatedElement, total, size int, urlFactory paginationURLFactory) (*Paginator, error) {","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/page/pagination.go#L342-L378","documentation":"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.","triggerScenarios":"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.","commonSituations":"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) }}`).","solutions":["Ensure the pager size passed to .Paginate is a positive integer","Fix `pagination.pagerSize` in site config to a value >= 1","If computing the size in templates, guard against zero before calling .Paginate"],"exampleFix":"// before\n{{ $size := sub $n $n }}{{ $pag := .Paginate .Pages $size }}\n// after\n{{ $size := default 10 $computed }}{{ $pag := .Paginate .Pages $size }}","handlingStrategy":"validation","validationCode":"{{ $size := 12 }}{{ if gt $size 0 }}{{ $pag := .Paginate .Pages $size }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When the pager size comes from front matter or site params, validate it is a positive integer before passing to .Paginate","Use a default: {{ $size := default 10 (int (.Params.pageSize | default 0)) }} and guard gt $size 0","Don't compute page size from arithmetic that can reach zero (e.g. len of an empty slice)"],"tags":["hugo","pagination","validation"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}