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

errors.ts

102 lines2.9 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 SyncNotInitializedError extends QueryCollectionError {
40 constructor() {
41 super(
42 `Collection must be in 'ready' state for manual sync operations. Sync not initialized yet.`,
43 )
44 this.name = `SyncNotInitializedError`
45 }
47​
48export class InvalidItemStructureError extends QueryCollectionError {
49 constructor(message: string) {
50 super(`Invalid item structure: ${message}`)
51 this.name = `InvalidItemStructureError`
52 }
54​
55export class ItemNotFoundError extends QueryCollectionError {
56 constructor(key: string | number) {
57 super(`Item with key '${key}' does not exist.`)
58 this.name = `ItemNotFoundError`
59 }
61​
62export class DuplicateKeyInBatchError extends QueryCollectionError {
63 constructor(key: string | number) {
64 super(`Duplicate key '${key}' found within batch operations`)
65 this.name = `DuplicateKeyInBatchError`
66 }
68​
69export class UpdateOperationItemNotFoundError extends QueryCollectionError {
70 constructor(key: string | number) {
71 super(`Update operation: Item with key '${key}' does not exist`)
72 this.name = `UpdateOperationItemNotFoundError`
73 }
75​
76export class DeleteOperationItemNotFoundError extends QueryCollectionError {
77 constructor(key: string | number) {
78 super(`Delete operation: Item with key '${key}' does not exist`)
79 this.name = `DeleteOperationItemNotFoundError`
80 }
82​
83export class InvalidSyncOperationError extends QueryCollectionError {
84 constructor(message: string) {
85 super(`Invalid sync operation: ${message}`)
86 this.name = `InvalidSyncOperationError`
87 }
89​
90export class UnknownOperationTypeError extends QueryCollectionError {
91 constructor(type: string) {
92 super(`Unknown operation type: ${type}`)
93 this.name = `UnknownOperationTypeError`
94 }
96​
97export class MissingKeyFieldError extends QueryCollectionError {
98 constructor(operation: string, message: string) {
99 super(`${operation} item must contain the key field: ${message}`)
100 this.name = `MissingKeyFieldError`
101 }