{"record":{"id":"fc94670af5164433","repo":"AlistGo/alist","slug":"page-can-t-1","errorCode":null,"errorMessage":"page can't < 1","messagePattern":"page can't < 1","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/model/search.go","lineNumber":32,"sourceCode":"\ntype SearchReq struct {\n\tParent   string `json:\"parent\"`\n\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":14,"sourceCodeEnd":43,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/internal/model/search.go#L14-L43","documentation":"Returned by SearchReq.Validate when the request's Page field is less than 1. Search pagination is 1-based, so page=0 or negative values are rejected before the search backend is queried. Usually surfaces as a 400 from the search handler.","triggerScenarios":"Calling the search API with page=0, a negative page, or omitting page when the binding default is zero.","commonSituations":"Client built with 0-based pagination copied from another API; form/JSON binding leaving the field at its Go zero value; off-by-one when decrementing past the first page in a UI.","solutions":["Send page >= 1 in the search request.","Default the page field to 1 client-side when the user has not paged yet.","Clamp page to 1 when computing it from an offset (page = offset/per_page)."],"exampleFix":"// before\nreq := model.SearchReq{Page: offset / perPage} // offset 0 => page 0\n\n// after\npage := offset/perPage + 1\nif page < 1 {\n    page = 1\n}\nreq := model.SearchReq{PageReq: model.PageReq{Page: page, PerPage: perPage}}","handlingStrategy":"validation","validationCode":"if req.Page < 1 { req.Page = 1 }\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":["Treat pages as 1-based everywhere in client code.","Compute page from offset with max(1, offset/per_page + 1).","Call Validate() before touching the search backend."],"tags":["validation","pagination","search","api","go"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}