feat: replace string-based errors with named error classes for better error handling#297
Merged
KyleAMathews merged 8 commits intomainfrom Jul 21, 2025
Merged
feat: replace string-based errors with named error classes for better error handling#297KyleAMathews merged 8 commits intomainfrom
KyleAMathews merged 8 commits intomainfrom
Conversation
… error handling This comprehensive update replaces all 139 string-based error throws throughout the TanStack DB codebase with 68 named error classes, providing better type safety and developer experience. Key changes: - Created centralized errors.ts with 68 named error classes organized by category - Updated all source files to use named errors instead of string-based errors - Updated all tests to use instanceof checks instead of string matching - Updated documentation with migration guide and best practices - Maintained exact same error messages and behavior for backward compatibility Breaking changes: - Error handling code using string matching will need to use instanceof checks - Some error message formatting may have minor changes 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: da03992 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
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 |
|
@tanstack/db-example-react-todo @tanstack/db
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Contributor
|
Size Change: 0 B Total Size: 52.6 kB ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 1.05 kB ℹ️ View Unchanged
|
samwillis
approved these changes
Jul 21, 2025
Collaborator
samwillis
left a comment
There was a problem hiding this comment.
Looks great!
maybe have the root errors extend a single TanStackDBError?
This refactor improves package separation by moving adapter-specific error classes from the core @tanstack/db package to their respective adapter packages. Changes: - Moved Electric DB errors to @tanstack/electric-db-collection/errors - Moved TrailBase DB errors to @tanstack/trailbase-db-collection/errors - Moved Query Collection errors to @tanstack/query-db-collection/errors - Updated imports in adapter files to use local error classes - Kept only generic/core errors in @tanstack/db - Updated changeset to reflect new package structure - Fixed linting issues (shadow variables and unnecessary conditions) Benefits: - Better package separation and encapsulation - Reduced core package size - Error classes are co-located with their usage - Each adapter manages its own error types 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
All error classes now inherit from TanStackDBError, enabling developers to catch any TanStack DB error with a single instanceof check while maintaining specific error types for detailed handling. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Collaborator
Author
|
ah yeah, a root |
Resolved conflicts in collection.ts and distinct.test.ts to integrate: - New collection indexing functionality from main - Named error classes from current branch - Updated test expectations to use DistinctRequiresSelectError 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…snapshots - Fix all adapter error classes to set proper error names instead of base class names - Update electric test snapshot to expect ExpectedNumberInAwaitTxIdError - Use createDepartmentsCollection in join tests for consistency - All tests now passing across all packages 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This comprehensive update replaces all 139 string-based error throws throughout the TanStack DB codebase with 68 named error classes, providing better type safety and developer experience.
Key Changes
Created centralized
errors.tswith 68 named error classes organized by category:Updated all source files to use named errors instead of string-based errors
Updated all tests to use
instanceofchecks instead of string matchingUpdated documentation with migration guide and best practices
Maintained exact same error messages and behavior for backward compatibility
Breaking Changes
instanceofchecksMigration Guide
Before:
After:
Benefits
instanceoferrors.tsTest Plan
🤖 Generated with Claude Code