{"record":{"id":"ef0cf74e3f4c2392","repo":"AlistGo/alist","slug":"per-page-can-t-1","errorCode":null,"errorMessage":"per_page can't < 1","messagePattern":"per_page can't < 1","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/model/search.go","lineNumber":35,"sourceCode":"\tKeywords string `json:\"keywords\"`\n\t// 0 for all, 1 for dir, 2 for file\n\tScope int `json:\"scope\"`\n\tPageReq\n}\n\ntype SearchNode struct {\n\tParent string `json:\"parent\" gorm:\"index\"`\n\tName   string `json:\"name\"`\n\tIsDir  bool   `json:\"is_dir\"`\n\tSize   int64  `json:\"size\"`\n}\n\nfunc (p *SearchReq) Validate() error {\n\tif p.Page < 1 {\n\t\treturn fmt.Errorf(\"page can't < 1\")\n\t}\n\tif p.PerPage < 1 {\n\t\treturn fmt.Errorf(\"per_page can't < 1\")\n\t}\n\treturn nil\n}\n\nfunc (s *SearchNode) Type() string {\n\treturn \"SearchNode\"\n}\n","sourceCodeStart":17,"sourceCodeEnd":43,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/internal/model/search.go#L17-L43","documentation":"Returned by SearchReq.Validate when PerPage is less than 1. The search backend needs a positive page size; per_page=0 or negative would produce empty or invalid limit/offset SQL. Surfaces as a 400 from the search handler.","triggerScenarios":"Calling search with per_page=0, negative, or omitting it when the binding default is zero.","commonSituations":"UI page-size selector allowing 0 or blank; client passing an unset config value; stress scripts sending per_page=0 hoping for 'all results'.","solutions":["Send per_page >= 1 (e.g. a sane default like 30).","Validate/clamp the page-size input in the client before sending.","If 'all results' is needed, implement explicit export logic rather than per_page=0."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if req.PerPage < 1 { req.PerPage = 30 } // sane default\nif err := req.Validate(); err != nil { /* 400 */ }","typeGuard":null,"tryCatchPattern":"if err := searchReq.Validate(); err != nil {\n    c.JSON(http.StatusBadRequest, gin.H{\"message\": err.Error()})\n    return\n}","preventionTips":["Always send an explicit per_page >= 1.","Clamp page-size selectors to a minimum of 1 (and a sane maximum) in the UI.","Do not use per_page=0 to mean 'unlimited' — it is rejected."],"tags":["validation","pagination","search","api","go"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}