-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
errors.dart
250 lines (200 loc) · 5.54 KB
/
errors.dart
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import 'service/channel.dart' as channel;
import 'support/utils.dart';
/// Base class for custom exceptions in the `cbl` package.
abstract class CouchbaseLiteException implements Exception {
/// A description of this exception.
String get message;
/// An optional error code specifies the cause of this exception.
Object? get code => null;
/// The [StackTrace] from the execution context where this exception
/// originated from.
///
/// When an exception originates in a different execution context than the
/// current one, this property contains the original stack trace, if it is
/// available.
StackTrace? get remoteStackTrace => channel.remoteStackTrace(this);
String get _typeName;
@override
String toString() => [
'$_typeName(',
[
message,
if (code != null) 'code: ${describeEnum(code!)}',
].join(', '),
')'
].join();
}
/// A specification of the cause of a [DatabaseException].
enum DatabaseErrorCode {
assertionFailed,
unimplemented,
unsupportedEncryption,
badRevisionId,
corruptRevisionData,
notOpen,
notFound,
conflict,
invalidParameter,
unexpectedError,
cantOpenFile,
iOError,
memoryError,
notWriteable,
corruptData,
busy,
notInTransaction,
transactionNotClosed,
unsupported,
notADatabaseFile,
wrongFormat,
crypto,
invalidQuery,
missingIndex,
invalidQueryParam,
remoteError,
databaseTooOld,
databaseTooNew,
badDocId,
cantUpgradeDatabase,
}
/// Exception throw when there is a failure interacting with a Couchbase Lite
/// database.
class DatabaseException extends CouchbaseLiteException {
/// Creates an exception which is thrown when there is a failure interacting
/// with a Couchbase Lite database.
DatabaseException(
this.message,
this.code, {
this.queryString,
this.errorPosition,
});
@override
final String message;
@override
final DatabaseErrorCode code;
/// If this is an query parsing exception the invalid query string.
final String? queryString;
/// If this is an query parsing exception the position of the error in the
/// [queryString].
final int? errorPosition;
@override
String toString() {
var result = super.toString();
if (queryString != null) {
if (errorPosition != null) {
result +=
'\n${highlightPosition(queryString!, offset: errorPosition!)}';
} else {
result += '\n$queryString';
}
}
return result;
}
@override
final _typeName = 'DatabaseException';
}
/// A specification of the cause of a [NetworkException].
enum NetworkErrorCode {
dnsFailure,
unknownHost,
timeout,
invalidURL,
tooManyRedirects,
tlsHandshakeFailed,
tlsCertExpired,
tlsCertUntrusted,
tlsClientCertRequired,
tlsClientCertRejected,
tlsCertUnknownRoot,
invalidRedirect,
unknown,
tlsCertRevoked,
tlsCertNameMismatch,
}
/// Exception thrown when there is a failure accessing the network.
class NetworkException extends CouchbaseLiteException {
/// Creates an exception which is thrown when there is a failure accessing the
/// network.
NetworkException(this.message, this.code);
@override
final String message;
@override
final NetworkErrorCode code;
@override
final _typeName = 'NetworkException';
}
/// A specification of the cause of a [HttpException].
enum HttpErrorCode {
/// Missing or incorrect user authentication.
authRequired,
/// User doesn't have permission to access resource.
forbidden,
/// Resource not found.
notFound,
/// Update conflict.
conflict,
/// HTTP proxy requires authentication.
proxyAuthRequired,
/// Data is too large to upload.
entityTooLarge,
/// HTCPCP/1.0 error (RFC 2324).
imATeapot,
/// Something's wrong with the server.
internalServerError,
/// Unimplemented server functionality.
notImplemented,
/// Service is down temporarily(?).
serviceUnavailable,
}
/// Exception thrown when there is an HTTP error.
class HttpException extends CouchbaseLiteException {
/// Creates an exception which is thrown when there is an HTTP error.
HttpException(this.message, this.code);
@override
final String message;
@override
final HttpErrorCode? code;
@override
final _typeName = 'HttpException';
}
/// A specification of the cause of a [WebSocketException].
enum WebSocketErrorCode {
/// Peer has to close, e.g. because host app is quitting.
goingAway,
/// Protocol violation: invalid framing data.
protocolError,
/// Message payload cannot be handled.
dataError,
/// TCP socket closed unexpectedly.
abnormalClose,
/// Unparseable WebSocket message.
badMessageFormat,
/// Message violated unspecified policy.
policyError,
/// Message is too large for peer to handle.
messageTooBig,
/// Peer doesn't provide a necessary extension.
missingExtension,
/// Can't fulfill request due to "unexpected condition".
cantFulfill,
}
/// Exception thrown when there is an WebSocket error.
class WebSocketException extends CouchbaseLiteException {
/// Creates an exception which is thrown when there is an WebSocket error.
WebSocketException(this.message, this.code);
@override
final String message;
@override
final WebSocketErrorCode? code;
@override
final _typeName = 'WebSocketException';
}
/// Exception thrown when JSON data is invalid.
class InvalidJsonException extends CouchbaseLiteException {
/// Creates an exception which is thrown when JSON data is invalid.
InvalidJsonException(this.message);
@override
final String message;
@override
final _typeName = 'InvalidJsonException';
}