{"record":{"id":"ee7bc3ee03db6a28","repo":"cloudreve/cloudreve","slug":"query-failed-with-paginiation-w","errorCode":null,"errorMessage":"query failed with paginiation: %w","messagePattern":"query failed with paginiation: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"inventory/dav_account.go","lineNumber":110,"sourceCode":"\treturn account.Save(ctx)\n}\n\nfunc (c *davAccountClient) Delete(ctx context.Context, id int) error {\n\treturn c.client.DavAccount.DeleteOneID(id).Exec(ctx)\n}\n\nfunc (c *davAccountClient) List(ctx context.Context, args *ListDavAccountArgs) (*ListDavAccountResult, error) {\n\tquery := c.listQuery(args)\n\n\tvar (\n\t\taccounts      []*ent.DavAccount\n\t\terr           error\n\t\tpaginationRes *PaginationResults\n\t)\n\taccounts, paginationRes, err = c.cursorPagination(ctx, query, args, 10)\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"query failed with paginiation: %w\", err)\n\t}\n\n\treturn &ListDavAccountResult{\n\t\tAccounts:          accounts,\n\t\tPaginationResults: paginationRes,\n\t}, nil\n}\n\nfunc (c *davAccountClient) cursorPagination(ctx context.Context, query *ent.DavAccountQuery, args *ListDavAccountArgs, paramMargin int) ([]*ent.DavAccount, *PaginationResults, error) {\n\tpageSize := capPageSize(c.maxSQlParam, args.PageSize, paramMargin)\n\tquery.Order(davaccount.ByID(sql.OrderDesc()))\n\n\tvar (\n\t\tpageToken *PageToken\n\t\terr       error\n\t)\n\tif args.PageToken != \"\" {\n\t\tpageToken, err = pageTokenFromString(args.PageToken, c.hasher, hashid.DavAccountID)","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/cloudreve/cloudreve/blob/20c95ad73f3a8bcb72887fea91ff31ab24fa1011/inventory/dav_account.go#L92-L128","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Unwrap and classify: if the cause contains \"invalid page token\", fix the token (error 132 guidance); otherwise treat as a DB-level failure.","Check DB health/Logs: connection count, lock waits, restarts around the failure time; for sqlite, ensure a single writer process.","Retry the request once with a fresh connection for transient driver errors (gone away / bad conn); on second failure, surface it.","If reproducible with a specific token, drop the token and list from the first page to confirm it is token-related versus DB-related."],"exampleFix":"// before\nreturn nil, fmt.Errorf(\"query failed with paginiation: %w\", err)\n\n// after (also fixes the misspelling)\nreturn nil, fmt.Errorf(\"query failed with pagination: %w\", err)","handlingStrategy":"retry","validationCode":"// Cheap liveness check before long list operations\nif err := db.PingContext(ctx); err != nil {\n    return nil, fmt.Errorf(\"db not ready, skip list: %w\", err)\n}","typeGuard":"func isDavPaginationFailure(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"query failed with paginiation\")\n}","tryCatchPattern":"var res *ListDavAccountResult\nerr := retry.Do(func() error {\n    var e error\n    res, e = c.List(ctx, args)\n    return e\n}, retry.OnRetry(func(n uint, e error) {\n    if strings.Contains(e.Error(), \"invalid page token\") {\n        panic(e) // not retryable: token problem\n    }\n}), retry.Attempts(2))","preventionTips":["Retry once on transient driver errors (connection reset, gone away); never retry token errors.","Run list endpoints against healthy DBs; avoid scheduling them during migrations/backups.","Set sane request contexts so queries fail fast rather than pile up."],"tags":["go","cloudreve","pagination","database","webdav","ent","typo"],"backgroundTag":null,"analyzedSha":"20c95ad73f3a8bcb72887fea91ff31ab24fa1011","analyzedAt":"2026-08-16T01:42:55.403Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}