Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

errors.ts

111 lines3.2 KB

1import { TanStackDBError } from '@tanstack/db'
2​
3// Query Collection Errors
4export class QueryCollectionError extends TanStackDBError {
5 constructor(message: string) {
6 super(message)
7 this.name = `QueryCollectionError`
8 }
9}
10​
11export class QueryKeyRequiredError extends QueryCollectionError {
12 constructor() {
13 super(`[QueryCollection] queryKey must be provided.`)
14 this.name = `QueryKeyRequiredError`
15 }
17​
18export class QueryFnRequiredError extends QueryCollectionError {
19 constructor() {
20 super(`[QueryCollection] queryFn must be provided.`)
21 this.name = `QueryFnRequiredError`
22 }
24​
25export class QueryClientRequiredError extends QueryCollectionError {
26 constructor() {
27 super(`[QueryCollection] queryClient must be provided.`)
28 this.name = `QueryClientRequiredError`
29 }
31​
32export class GetKeyRequiredError extends QueryCollectionError {
33 constructor() {
34 super(`[QueryCollection] getKey must be provided.`)
35 this.name = `GetKeyRequiredError`
36 }
38​
39export class InitialDataInOnDemandModeError extends QueryCollectionError {
40 constructor() {
41 super(
42 `[QueryCollection] initialData and initialDataUpdatedAt are only supported when syncMode is 'eager'. Seed or hydrate the exact Query cache key for on-demand subsets instead.`,
43 )
44 this.name = `InitialDataInOnDemandModeError`
45 }
47​
48export class SyncNotInitializedError extends QueryCollectionError {
49 constructor() {
50 super(
51 `Collection must be in 'ready' state for manual sync operations. Sync not initialized yet.`,
52 )
53 this.name = `SyncNotInitializedError`
54 }
56​
57export class InvalidItemStructureError extends QueryCollectionError {
58 constructor(message: string) {
59 super(`Invalid item structure: ${message}`)
60 this.name = `InvalidItemStructureError`
61 }
63​
64export class ItemNotFoundError extends QueryCollectionError {
65 constructor(key: string | number) {
66 super(`Item with key '${key}' does not exist.`)
67 this.name = `ItemNotFoundError`
68 }
70​
71export class DuplicateKeyInBatchError extends QueryCollectionError {
72 constructor(key: string | number) {
73 super(`Duplicate key '${key}' found within batch operations`)
74 this.name = `DuplicateKeyInBatchError`
75 }
77​
78export class UpdateOperationItemNotFoundError extends QueryCollectionError {
79 constructor(key: string | number) {
80 super(`Update operation: Item with key '${key}' does not exist`)
81 this.name = `UpdateOperationItemNotFoundError`
82 }
84​
85export class DeleteOperationItemNotFoundError extends QueryCollectionError {
86 constructor(key: string | number) {
87 super(`Delete operation: Item with key '${key}' does not exist`)
88 this.name = `DeleteOperationItemNotFoundError`
89 }
91​
92export class InvalidSyncOperationError extends QueryCollectionError {
93 constructor(message: string) {
94 super(`Invalid sync operation: ${message}`)
95 this.name = `InvalidSyncOperationError`
96 }
98​
99export class UnknownOperationTypeError extends QueryCollectionError {
100 constructor(type: string) {
101 super(`Unknown operation type: ${type}`)
102 this.name = `UnknownOperationTypeError`
103 }
105​
106export class MissingKeyFieldError extends QueryCollectionError {
107 constructor(operation: string, message: string) {
108 super(`${operation} item must contain the key field: ${message}`)
109 this.name = `MissingKeyFieldError`
110 }