Skip to content
Source
Sign inSign up
TanStack/db

feat: add error tracking and retry methods to query collection utils #441

Mergedlucasweng(GitHub profile, opens in a new tab)merged 7 commits intomain fromrefs/pull/441/headmerged by KyleAMathews(GitHub profile, opens in a new tab)

Summary

  • Add lastError, isError, errorCount and clearError methods to query collection utils per https://github.com/TanStack/db/issues/347
  • Add new tests to verify error state tracking, ensure clearError triggers a refetch, and collection operations function as expected with cached data while in an error state.

Note: To keep the diff focused, this PR does not implement onError, onSettled, and useErrorBoundary. These will be addressed in a separate PR.

Test Plan

  • Tests pass locally
  • Package builds successfully
    1. More templates

      @tanstack/db

      npm i https://pkg.pr.new/@tanstack/db@441

      @tanstack/db-ivm

      npm i https://pkg.pr.new/@tanstack/db-ivm@441

      @tanstack/electric-db-collection

      npm i https://pkg.pr.new/@tanstack/electric-db-collection@441

      @tanstack/query-db-collection

      npm i https://pkg.pr.new/@tanstack/query-db-collection@441

      @tanstack/react-db

      npm i https://pkg.pr.new/@tanstack/react-db@441

      @tanstack/solid-db

      npm i https://pkg.pr.new/@tanstack/solid-db@441

      @tanstack/svelte-db

      npm i https://pkg.pr.new/@tanstack/svelte-db@441

      @tanstack/trailbase-db-collection

      npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@441

      @tanstack/vue-db

      npm i https://pkg.pr.new/@tanstack/vue-db@441

      commit: d7e8009

    2. OutdatedResolvedby lucasweng(GitHub profile, opens in a new tab)
    3. 🦋 Changeset detected

      Latest commit: d7e8009123bcf738d82f86103dcafb20e7d863c4

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 2 packages
      NameType
      @tanstack/query-db-collectionPatch
      @tanstack/db-example-react-todoPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    4. ChatGPT's review https://chatgpt.com/share/68add190-8f64-800c-bc40-1218ca9d9e7f

      Thanks @KyleAMathews. I updated the error tracking logic and added a retry test in a7cf838 per the review.

      I didn't adopt the suggestion to have clearError throw on refetch failure though. The method's contract is to reset the error state, and throwing an exception could make it appear that the error state wasn't successfully cleared when it actually was, which may confuse users. If callers need to handle refetch failures, they can check the errorCount or isError state after calling clearError. Would like to know your thoughts on this 🙏

      Edited: https://github.com/TanStack/db/pull/441/commits/62d3e864d35ba1791529a2341bd7414aa2ee316c added documentation for error tracking utils. The onError example in https://github.com/TanStack/db/issues/347 will be included after onError is implemented.

      Edited: https://github.com/TanStack/db/pull/441/commits/1947a5751f23daa6f678e51d4a06f481c0f02c0b Thinking about clearError again, it's simpler to just throw an error if the refetch fails. This is easier for users to handle than checking errorCount after it's been reset. To avoid the confusion I mentioned, I updated the JSDoc for clearError explaining that it can throw an error if the refetch fails."

    5. KyleAMathews(GitHub profile, opens in a new tab) approved these changes

      Great work!

      Sorry for the delay getting this in. I'm just starting to come back from parental leave.

    6. @lucasweng btw I made a few follow-up issues (linked here in the PR). Feel free to pick up any of them!

    7. Sorry for the delay getting this in. I'm just starting to come back from parental leave.

      No problems at all! Thanks for taking time to look into this 🙏🏻

Sign in to join this conversation.