cloudreve/cloudreve · error

query failed with paginiation: %w

Error message

query failed with paginiation: %w

What it means

Wrapped by davAccountClient.List when its cursorPagination pass (query construction, optional token decode, queryPaged.All fetch, or next-token generation) returns an error. It aggregates several distinct failures: malformed page token (see 132), database errors from the ent All(ctx) query, and next-token encoding. The message contains a misspelling ("paginiation") that is useful to grep for. The underlying %w is preserved, so errors.Is/As still work on the cause.

Source

Thrown at inventory/dav_account.go:110

	return account.Save(ctx)
}

func (c *davAccountClient) Delete(ctx context.Context, id int) error {
	return c.client.DavAccount.DeleteOneID(id).Exec(ctx)
}

func (c *davAccountClient) List(ctx context.Context, args *ListDavAccountArgs) (*ListDavAccountResult, error) {
	query := c.listQuery(args)

	var (
		accounts      []*ent.DavAccount
		err           error
		paginationRes *PaginationResults
	)
	accounts, paginationRes, err = c.cursorPagination(ctx, query, args, 10)

	if err != nil {
		return nil, fmt.Errorf("query failed with paginiation: %w", err)
	}

	return &ListDavAccountResult{
		Accounts:          accounts,
		PaginationResults: paginationRes,
	}, nil
}

func (c *davAccountClient) cursorPagination(ctx context.Context, query *ent.DavAccountQuery, args *ListDavAccountArgs, paramMargin int) ([]*ent.DavAccount, *PaginationResults, error) {
	pageSize := capPageSize(c.maxSQlParam, args.PageSize, paramMargin)
	query.Order(davaccount.ByID(sql.OrderDesc()))

	var (
		pageToken *PageToken
		err       error
	)
	if args.PageToken != "" {
		pageToken, err = pageTokenFromString(args.PageToken, c.hasher, hashid.DavAccountID)

View on GitHub (pinned to 20c95ad73f)

Solutions

  1. Unwrap and classify: if the cause contains "invalid page token", fix the token (error 132 guidance); otherwise treat as a DB-level failure.
  2. Check DB health/Logs: connection count, lock waits, restarts around the failure time; for sqlite, ensure a single writer process.
  3. Retry the request once with a fresh connection for transient driver errors (gone away / bad conn); on second failure, surface it.
  4. If reproducible with a specific token, drop the token and list from the first page to confirm it is token-related versus DB-related.

Example fix

// before
return nil, fmt.Errorf("query failed with paginiation: %w", err)

// after (also fixes the misspelling)
return nil, fmt.Errorf("query failed with pagination: %w", err)
Defensive patterns

Strategy: retry

Validate before calling

// Cheap liveness check before long list operations
if err := db.PingContext(ctx); err != nil {
    return nil, fmt.Errorf("db not ready, skip list: %w", err)
}

Type guard

func isDavPaginationFailure(err error) bool {
    return err != nil && strings.Contains(err.Error(), "query failed with paginiation")
}

Try / catch

var res *ListDavAccountResult
err := retry.Do(func() error {
    var e error
    res, e = c.List(ctx, args)
    return e
}, retry.OnRetry(func(n uint, e error) {
    if strings.Contains(e.Error(), "invalid page token") {
        panic(e) // not retryable: token problem
    }
}), retry.Attempts(2))

Prevention

When it happens

Trigger: Calling DavAccount List when: args.PageToken is invalid (propagates as "invalid page token" wrapped here); the DB is unreachable/restarted mid-query (MySQL "invalid connection", Postgres context deadline, sqlite locked); the query exceeds server limits; or hash-ID bookkeeping fails while minting the next token.

Common situations: Admin frontends listing WebDAV accounts against a flaky DB; long-lived sessions after a DB failover where the pooled connections went stale; requests issued while a migration (error 122) holds schema locks; oversized page_size interacting with driver parameter caps (mitigated internally by capPageSize).

Related errors


AI-assisted analysis of cloudreve/cloudreve@20c95ad73f (2026-08-16). Data as JSON: /api/errors/ee7bc3ee03db6a28. Report an issue: GitHub.