AlistGo/alist · warning

page can't < 1

Error message

page can't < 1

What it means

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.

Source

Thrown at internal/model/search.go:32

type SearchReq struct {
	Parent   string `json:"parent"`
	Keywords string `json:"keywords"`
	// 0 for all, 1 for dir, 2 for file
	Scope int `json:"scope"`
	PageReq
}

type SearchNode struct {
	Parent string `json:"parent" gorm:"index"`
	Name   string `json:"name"`
	IsDir  bool   `json:"is_dir"`
	Size   int64  `json:"size"`
}

func (p *SearchReq) Validate() error {
	if p.Page < 1 {
		return fmt.Errorf("page can't < 1")
	}
	if p.PerPage < 1 {
		return fmt.Errorf("per_page can't < 1")
	}
	return nil
}

func (s *SearchNode) Type() string {
	return "SearchNode"
}

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Send page >= 1 in the search request.
  2. Default the page field to 1 client-side when the user has not paged yet.
  3. Clamp page to 1 when computing it from an offset (page = offset/per_page).

Example fix

// before
req := model.SearchReq{Page: offset / perPage} // offset 0 => page 0

// after
page := offset/perPage + 1
if page < 1 {
    page = 1
}
req := model.SearchReq{PageReq: model.PageReq{Page: page, PerPage: perPage}}
Defensive patterns

Strategy: validation

Validate before calling

if req.Page < 1 { req.Page = 1 }
if err := req.Validate(); err != nil { /* 400 */ }

Try / catch

if err := searchReq.Validate(); err != nil {
    c.JSON(http.StatusBadRequest, gin.H{"message": err.Error()})
    return
}

Prevention

When it happens

Trigger: Calling the search API with page=0, a negative page, or omitting page when the binding default is zero.

Common situations: 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.

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/fc94670af5164433. Report an issue: GitHub.