-
-
Notifications
You must be signed in to change notification settings - Fork 626
/
errors.d.ts
176 lines (140 loc) · 5.14 KB
/
errors.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { IndexableTypeArrayReadonly } from "./indexable-type";
/** DexieError
*
* Common base class for all errors originating from Dexie.js except TypeError,
* SyntaxError and RangeError.
*
* http://dexie.org/docs/DexieErrors/DexieError
*
*/
export interface DexieError extends Error {
name: string;
message: string;
stack: string;
inner: any;
toString(): string;
}
/**
* List of the names of auto-generated error classes that extends DexieError
* and shares the interface of DexieError.
*
* Each error should be documented at http://dexie.org/docs/DexieErrors/Dexie.<errname>
*
* The generic type DexieExceptionClasses is a map of full error name to
* error constructor. The DexieExceptionClasses is mixed in into Dexie,
* so that it is always possible to throw or catch certain errors via
* Dexie.ErrorName. Example:
*
* try {
* throw new Dexie.InvalidTableError("Invalid table foo", innerError?);
* } catch (err) {
* if (err instanceof Dexie.InvalidTableError) {
* // Could also have check for err.name === "InvalidTableError", or
* // err.name === Dexie.errnames.InvalidTableError.
* console.log("Seems to be an invalid table here...");
* } else {
* throw err;
* }
* }
*/
export type DexieErrors = {
// http://dexie.org/docs/DexieErrors/Dexie.OpenFailedError
OpenFailed: 'OpenFailedError',
// http://dexie.org/docs/DexieErrors/Dexie.VersionChangeError
VersionChange: 'VersionChangeError',
// http://dexie.org/docs/DexieErrors/Dexie.SchemaError
Schema: 'SchemaError',
// http://dexie.org/docs/DexieErrors/Dexie.UpgradeError
Upgrade: 'UpgradeError',
// http://dexie.org/docs/DexieErrors/Dexie.InvalidTableError
InvalidTable: 'InvalidTableError',
// http://dexie.org/docs/DexieErrors/Dexie.MissingAPIError
MissingAPI: 'MissingAPIError',
// http://dexie.org/docs/DexieErrors/Dexie.NoSuchDatabaseError
NoSuchDatabase: 'NoSuchDatabaseError',
// http://dexie.org/docs/DexieErrors/Dexie.InvalidArgumentError
InvalidArgument: 'InvalidArgumentError',
// http://dexie.org/docs/DexieErrors/Dexie.SubTransactionError
SubTransaction: 'SubTransactionError',
// http://dexie.org/docs/DexieErrors/Dexie.UnsupportedError
Unsupported: 'UnsupportedError',
// http://dexie.org/docs/DexieErrors/Dexie.InternalError
Internal: 'InternalError',
// http://dexie.org/docs/DexieErrors/Dexie.DatabaseClosedError
DatabaseClosed: 'DatabaseClosedError',
// http://dexie.org/docs/DexieErrors/Dexie.PrematureCommitError
PrematureCommit: 'PrematureCommitError',
// http://dexie.org/docs/DexieErrors/Dexie.ForeignAwaitError
ForeignAwait: 'ForeignAwaitError',
// http://dexie.org/docs/DexieErrors/Dexie.UnknownError
Unknown: 'UnknownError',
// http://dexie.org/docs/DexieErrors/Dexie.ConstraintError
Constraint: 'ConstraintError',
// http://dexie.org/docs/DexieErrors/Dexie.DataError
Data: 'DataError',
// http://dexie.org/docs/DexieErrors/Dexie.TransactionInactiveError
TransactionInactive: 'TransactionInactiveError',
// http://dexie.org/docs/DexieErrors/Dexie.ReadOnlyError
ReadOnly: 'ReadOnlyError',
// http://dexie.org/docs/DexieErrors/Dexie.VersionError
Version: 'VersionError',
// http://dexie.org/docs/DexieErrors/Dexie.NotFoundError
NotFound: 'NotFoundError',
// http://dexie.org/docs/DexieErrors/Dexie.InvalidStateError
InvalidState: 'InvalidStateError',
// http://dexie.org/docs/DexieErrors/Dexie.InvalidAccessError
InvalidAccess: 'InvalidAccessError',
// http://dexie.org/docs/DexieErrors/Dexie.AbortError
Abort: 'AbortError',
// http://dexie.org/docs/DexieErrors/Dexie.TimeoutError
Timeout: 'TimeoutError',
// http://dexie.org/docs/DexieErrors/Dexie.QuotaExceededError
QuotaExceeded: 'QuotaExceededError',
// http://dexie.org/docs/DexieErrors/Dexie.DataCloneError
DataClone: 'DataCloneError'
}
/** ModifyError
*
* http://dexie.org/docs/DexieErrors/Dexie.ModifyError
*/
export interface ModifyError extends DexieError {
failures: Array<any>;
failedKeys: IndexableTypeArrayReadonly;
successCount: number;
}
/** BulkError
*
* http://dexie.org/docs/DexieErrors/Dexie.BulkError
*/
export interface BulkError extends DexieError {
failures: Error[];
failuresByPos: {[operationNumber: number]: Error};
}
export interface DexieErrorConstructor {
new(msg?: string, inner?: Object) : DexieError;
new(inner: Object): DexieError;
prototype: DexieError;
}
export interface ModifyErrorConstructor {
new (
msg?:string,
failures?: any[],
successCount?: number,
failedKeys?: IndexableTypeArrayReadonly) : ModifyError;
prototype: ModifyError;
}
export interface BulkErrorConstructor {
new (msg?:string, failures?: {[operationNumber: number]: Error}) : BulkError;
prototype: BulkError;
}
export type ExceptionAliasSet = {[ShortName in keyof DexieErrors]: DexieErrorConstructor} & {
Dexie: DexieErrorConstructor,
Modify: ModifyErrorConstructor;
Bulk: BulkErrorConstructor;
}
export type ExceptionSet = {[P in DexieErrors[keyof DexieErrors]]: DexieErrorConstructor};
export type DexieExceptionClasses = ExceptionSet & {
DexieError: DexieErrorConstructor,
ModifyError: ModifyErrorConstructor;
BulkError: BulkErrorConstructor;
}