You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Replace string-based errors with named error classes for better error handling
9
+
10
+
This comprehensive update replaces all string-based error throws throughout the TanStack DB codebase with named error classes, providing better type safety and developer experience.
11
+
12
+
## New Features
13
+
14
+
-**Root `TanStackDBError` class** - all errors inherit from a common base for unified error handling
15
+
-**Named error classes** organized by package and functional area
16
+
-**Type-safe error handling** using `instanceof` checks instead of string matching
17
+
-**Package-specific error definitions** - each adapter has its own error classes
18
+
-**Better IDE support** with autocomplete for error types
19
+
20
+
## Package Structure
21
+
22
+
### Core Package (`@tanstack/db`)
23
+
24
+
Contains generic errors used across the ecosystem:
25
+
26
+
- Collection configuration, state, and operation errors
27
+
- Transaction lifecycle and mutation errors
28
+
- Query building, compilation, and execution errors
29
+
- Storage and serialization errors
30
+
31
+
### Adapter Packages
32
+
33
+
Each adapter now exports its own specific error classes:
Copy file name to clipboardExpand all lines: docs/error-handling.md
+40-6Lines changed: 40 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,19 @@ TanStack DB provides comprehensive error handling capabilities to ensure robust
9
9
10
10
## Error Types
11
11
12
+
TanStack DB provides named error classes for better error handling and type safety. All error classes can be imported from `@tanstack/db` (or more commonly, the framework-specific package e.g. `@tanstack/react-db`):
13
+
14
+
```ts
15
+
import {
16
+
SchemaValidationError,
17
+
CollectionInErrorStateError,
18
+
DuplicateKeyError,
19
+
MissingHandlerError,
20
+
TransactionError,
21
+
// ... and many more
22
+
} from"@tanstack/db"
23
+
```
24
+
12
25
### SchemaValidationError
13
26
14
27
Thrown when data doesn't match the collection's schema during insert or update operations:
@@ -168,10 +181,12 @@ try {
168
181
Collections in an `error` state cannot perform operations and must be manually recovered:
0 commit comments