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

errors.ts

118 lines3.4 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 InvalidQueryResultError extends QueryCollectionError {
49 constructor(message: string) {
50 super(message)
51 this.name = `InvalidQueryResultError`
52 }
54​
55export class SyncNotInitializedError extends QueryCollectionError {
56 constructor() {
57 super(
58 `Collection must be in 'ready' state for manual sync operations. Sync not initialized yet.`,
59 )
60 this.name = `SyncNotInitializedError`
61 }
63​
64export class InvalidItemStructureError extends QueryCollectionError {
65 constructor(message: string) {
66 super(`Invalid item structure: ${message}`)
67 this.name = `InvalidItemStructureError`
68 }
70​
71export class ItemNotFoundError extends QueryCollectionError {
72 constructor(key: string | number) {
73 super(`Item with key '${key}' does not exist.`)
74 this.name = `ItemNotFoundError`
75 }
77​
78export class DuplicateKeyInBatchError extends QueryCollectionError {
79 constructor(key: string | number) {
80 super(`Duplicate key '${key}' found within batch operations`)
81 this.name = `DuplicateKeyInBatchError`
82 }
84​
85export class UpdateOperationItemNotFoundError extends QueryCollectionError {
86 constructor(key: string | number) {
87 super(`Update operation: Item with key '${key}' does not exist`)
88 this.name = `UpdateOperationItemNotFoundError`
89 }
91​
92export class DeleteOperationItemNotFoundError extends QueryCollectionError {
93 constructor(key: string | number) {
94 super(`Delete operation: Item with key '${key}' does not exist`)
95 this.name = `DeleteOperationItemNotFoundError`
96 }
98​
99export class InvalidSyncOperationError extends QueryCollectionError {
100 constructor(message: string) {
101 super(`Invalid sync operation: ${message}`)
102 this.name = `InvalidSyncOperationError`
103 }
105​
106export class UnknownOperationTypeError extends QueryCollectionError {
107 constructor(type: string) {
108 super(`Unknown operation type: ${type}`)
109 this.name = `UnknownOperationTypeError`
110 }
112​
113export class MissingKeyFieldError extends QueryCollectionError {
114 constructor(operation: string, message: string) {
115 super(`${operation} item must contain the key field: ${message}`)
116 this.name = `MissingKeyFieldError`
117 }