cli/cli · error

limit must be greater than 0 and less than or equal to %d

Error message

limit must be greater than 0 and less than or equal to %d

What it means

FetchParams.Validate enforces 0 < Limit <= maxLimitForFlag. The GitHub attestations endpoint is paginated and the library fetches until Limit is reached; a zero/negative limit would never fetch anything and an oversized limit would page the API excessively, so both are rejected up front.

Source

Thrown at pkg/cmd/attestation/api/client.go:47

// Allow injecting backoff interval in tests.
var getAttestationRetryInterval = time.Millisecond * 200

// FetchParams are the parameters for fetching attestations from the GitHub API
type FetchParams struct {
	Digest        string
	Limit         int
	Owner         string
	PredicateType string
	Repo          string
	Initiator     string
}

func (p *FetchParams) Validate() error {
	if p.Digest == "" {
		return fmt.Errorf("digest must be provided")
	}
	if p.Limit <= 0 || p.Limit > maxLimitForFlag {
		return fmt.Errorf("limit must be greater than 0 and less than or equal to %d", maxLimitForFlag)
	}
	if p.Repo == "" && p.Owner == "" {
		return fmt.Errorf("owner or repo must be provided")
	}
	return nil
}

// githubApiClient makes REST calls to the GitHub API
type githubApiClient interface {
	REST(hostname, method, p string, body io.Reader, data interface{}) error
	RESTWithNext(hostname, method, p string, body io.Reader, data interface{}) (string, error)
}

// httpClient makes HTTP calls to all non-GitHub API endpoints
type httpClient interface {
	Get(url string) (*http.Response, error)
}

View on GitHub (pinned to 0eeec0b92e)

Solutions

  1. Set Limit explicitly, e.g. FetchParams{Digest: d, Repo: r, Limit: 30}
  2. Keep it within the documented maximum (maxLimitForFlag); if you truly need more, page through multiple calls
  3. Default your own wrapper to a sane value (e.g. 30) whenever the user omits one

Example fix

// before
params := api.FetchParams{Digest: digest, Repo: repo}
// after
params := api.FetchParams{Digest: digest, Repo: repo, Limit: 30}
Defensive patterns

Strategy: validation

Validate before calling

const defaultLimit = 30
if params.Limit == 0 { params.Limit = defaultLimit }
if params.Limit < 1 || params.Limit > maxLimitForFlag {
    return fmt.Errorf("limit must be in (0, %d]", maxLimitForFlag)
}

Try / catch

if err := params.Validate(); err != nil {
    if strings.Contains(err.Error(), "limit must be greater than 0") {
        params.Limit = 30
        err = params.Validate()
    }
}

Prevention

When it happens

Trigger: Calling GetByDigest with FetchParams{Limit: 0} (the Go zero value, i.e. forgetting to set Limit) or Limit > maxLimitForFlag; CLI users hitting the cap with an arbitrarily large --limit.

Common situations: Library callers constructing FetchParams without initializing Limit because 0 is the natural default; scripts bumping --limit to 'get everything'; version changes that altered the maximum.

Related errors


AI-assisted analysis of cli/cli@0eeec0b92e (2026-08-15). Data as JSON: /api/errors/6ffbcf3dce7ee4f2. Report an issue: GitHub.