Skip to content

feat(query-core): add retryAttempt to query error callback context#10843

Open
raashish1601 wants to merge 1 commit into
TanStack:mainfrom
raashish1601:fix/query-error-context-retry-attempt
Open

feat(query-core): add retryAttempt to query error callback context#10843
raashish1601 wants to merge 1 commit into
TanStack:mainfrom
raashish1601:fix/query-error-context-retry-attempt

Conversation

@raashish1601
Copy link
Copy Markdown
Contributor

@raashish1601 raashish1601 commented May 30, 2026

Closes #10713
\nThis thread-safe fix adds the retry attempt count to query cache onError context as requested.
\n- Query cache callback now receives (error, query, { retryAttempt }).

  • Retry attempt tracks the latest failed retry count from Retryer before final failure.
  • Added focused queryCache tests for both default and retried failure cases.

Summary by CodeRabbit

  • New Features
    • Error callbacks now include retry attempt information in their context, providing developers with visibility into which retry iteration encountered the error during query execution. This enables more precise error tracking, enhanced debugging capabilities, and better failure analysis for troubleshooting query issues across applications.

Review Change Stack

Signed-off-by: Raashish Aggarwal <94279692+raashish1601@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 32f6d316-6ebd-424f-b81c-bd9bd02a044a

📥 Commits

Reviewing files that changed from the base of the PR and between 7fa2781 and ed03356.

📒 Files selected for processing (3)
  • packages/query-core/src/__tests__/queryCache.test.tsx
  • packages/query-core/src/query.ts
  • packages/query-core/src/queryCache.ts

📝 Walkthrough

Walkthrough

The PR adds retry attempt tracking to query error callbacks. The QueryCacheConfig.onError signature is updated to include retryAttempt in the context. Query.fetch now tracks the latest failure count across retryer invocations and passes it to the onError callback. Tests verify the callback receives correct retry counts.

Changes

Retry Attempt in Error Callback Context

Layer / File(s) Summary
Error callback contract with retry context
packages/query-core/src/queryCache.ts
QueryCacheConfig.onError callback signature updated to include retryAttempt: number in the context argument.
Query fetch retry tracking and callback wiring
packages/query-core/src/query.ts
Query.fetch introduces local state to track the latest retryer failure count, updates it on retry failures via the onFail handler, and passes it as context metadata when invoking the onError cache callback.
Test coverage for retry context in error callbacks
packages/query-core/src/__tests__/queryCache.test.tsx
Tests verify that onError receives context with retryAttempt: 0 on immediate failure and retryAttempt: 2 when retry: 2 is configured.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 A hop and a bound, the retry count's found,
Error context now rings with attempts around,
Callbacks know at last, how many retries have passed,
Better error handling, built to last! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding retryAttempt to the query error callback context.
Description check ✅ Passed The description addresses the linked issue (#10713), explains the change clearly, and mentions tests added. However, it lacks completion of the template's checklist sections.
Linked Issues check ✅ Passed The PR fully implements the requested feature from #10713: retryAttempt is added to the error callback context, allowing differentiated error handling based on retry attempts.
Out of Scope Changes check ✅ Passed All changes are focused and in-scope: updating callback signature, adding retry tracking, and adding tests specific to the retryAttempt feature.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: add retryAttempt to query error callback context

1 participant