{"record":{"id":"c8466d706de82db1","repo":"gohugoio/hugo","slug":"pager-size-must-be-a-positive-integer","errorCode":null,"errorMessage":"'pager size' must be a positive integer","messagePattern":"'pager size' must be a positive integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pagination.go","lineNumber":276,"sourceCode":"\t\tsplit = append(split, pg)\n\t}\n\n\treturn split\n}\n\nfunc ResolvePagerSize(conf config.AllProvider, options ...any) (int, error) {\n\tif len(options) == 0 {\n\t\treturn conf.Pagination().PagerSize, nil\n\t}\n\n\tif len(options) > 1 {\n\t\treturn -1, errors.New(\"too many arguments, 'pager size' is currently the only option\")\n\t}\n\n\tpas, err := cast.ToIntE(options[0])\n\n\tif err != nil || pas <= 0 {\n\t\treturn -1, errors.New((\"'pager size' must be a positive integer\"))\n\t}\n\n\treturn pas, nil\n}\n\nfunc Paginate(td TargetPathDescriptor, seq any, pagerSize int) (*Paginator, error) {\n\tif pagerSize <= 0 {\n\t\treturn nil, errors.New(\"'paginate' configuration setting must be positive to paginate\")\n\t}\n\n\turlFactory := newPaginationURLFactory(td)\n\n\tvar paginator *Paginator\n\n\tgroups, ok, err := ToPagesGroup(seq)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/page/pagination.go#L258-L294","documentation":"When exactly one option is given to `ResolvePagerSize`, it is cast to an int and must be positive (pagination.go:273-277). Zero, negative, or non-integer values are rejected because they would produce an empty or invalid paginator.","triggerScenarios":"Calling `{{ .Paginate $pages 0 }}`, `{{ .Paginate $pages -1 }}`, or `{{ .Paginate $pages \"ten\" }}` — the option fails to cast to a positive int.","commonSituations":"Passing a string instead of a number; passing 0 thinking it means \"default\"; arithmetic that underflows to zero or negative; typo in a computed pager size.","solutions":["Pass a positive integer literal or variable, e.g. `{{ .Paginate $pages 12 }}`.","If you want the configured default, omit the option entirely.","Ensure any computed size is clamped to >= 1."],"exampleFix":"{{/* before */}}\n{{ .Paginate $pages 0 }}\n\n{{/* after */}}\n{{ .Paginate $pages 12 }}","handlingStrategy":"validation","validationCode":"n, err := cast.ToIntE(opt)\nif err != nil || n <= 0 { return errors.New(\"'pager size' must be a positive integer\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass a positive integer for pager size.","Omit the option for the configured default."],"tags":["hugo","templates","pagination","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}