TanStack / TanStack/db

Document QueryCollection clearError() throwing behavior

Open
#538 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

query-collection
Dominant language
TypeScript
Stars
3.9k
Forks
266
Avg merge
1d 4h
Merged PRs (30d)
55

Description

Relates to: PR #441 ("add error tracking and retry methods to query collection utils")
Scope: Documentation / DX
Breaking changes: None (documenting existing behavior)

Summary

QueryCollection.utils.clearError() can throw errors when the refetch fails, but this behavior is not documented. Users need clear guidance on proper error handling patterns.

Current Implementation

// In packages/query-db-collection/src/query.ts:735-740
clearError: () => {
  lastError = undefined
  errorCount = 0
  lastErrorUpdatedAt = 0
  return refetch({ throwOnError: true }) // This can throw!
}

The method does throw on refetch failure, but this isn't documented anywhere.

Proposed Documentation

Add to error handling guide and JSDoc:

/**
 * Clear the error state and trigger a refetch of the query
 * @returns Promise that resolves when the refetch completes successfully
 * @throws Error if the refetch fails
 * @example
 * try {
 *   await collection.utils.clearError()
 *   // success: error state cleared; data refreshed
 * } catch (e) {
 *   // still in error; show toast/backoff, etc.
 * }
 */
clearError: () => Promise<void>

Acceptance Criteria

  • Error handling guide explicitly states that clearError() throws on failure
  • JSDoc includes @throws annotation with example
  • Example uses try/catch pattern
  • Document interaction with disabled queries (when combined with exact refetch targeting)
  • Add to QueryCollectionUtils interface documentation

Additional Context

This is especially important when combined with the exact refetch targeting (#537), as disabled/unobserved queries may behave differently.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading packages/query-db-collection/src/query.ts around lines 735-740 and the QueryCollectionUtils interface documentation to confirm clearError() behavior. Locate the error handling guide and review the disabled-query and exact-refetch context from the issue. Done means the guide, JSDoc, interface documentation, and try/catch example all explain successful refetches and thrown failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.