• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / 2214

10 Apr 2024 11:21PM UTC coverage: 91.813% (-0.8%) from 92.623%
2214

push

Evergreen

web-flow
Add missing availability checks for SecCopyErrorMessageString (#7577)

This requires iOS 11.3 and we currently target iOS 11.

94848 of 175770 branches covered (53.96%)

7 of 22 new or added lines in 2 files covered. (31.82%)

1815 existing lines in 77 files now uncovered.

242945 of 264608 relevant lines covered (91.81%)

6136478.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.77
/src/realm/error_codes.cpp
1
/*************************************************************************
2
 *
3
 * Copyright 2021 Realm Inc.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 **************************************************************************/
18

19
#include <realm/error_codes.hpp>
20
#include <realm/util/assert.hpp>
21

22
#include <iostream>
23
#include <string_view>
24
#include <algorithm>
25
#include <cstring>
26

27
namespace realm {
28

29
ErrorCategory ErrorCodes::error_categories(Error code)
30
{
30,492✔
31
    switch (code) {
30,492✔
32
        case OK:
✔
33
            break;
×
34

35
        case AddressSpaceExhausted:
210✔
36
        case BadVersion:
216✔
37
        case BrokenInvariant:
228✔
38
        case CallbackFailed:
270✔
39
        case MaximumFileSizeExceeded:
276✔
40
        case MultipleSyncAgents:
291✔
41
        case NoSubscriptionForWrite:
300✔
42
        case NotCloneable:
315✔
43
        case ObjectAlreadyExists:
339✔
44
        case OutOfDiskSpace:
345✔
45
        case OutOfMemory:
351✔
46
        case RangeError:
357✔
47
        case RuntimeError:
390✔
48
        case SchemaVersionMismatch:
396✔
49
        case UnsupportedFileFormatVersion:
402✔
50
        case OperationAborted:
408✔
51
            return ErrorCategory().set(ErrorCategory::runtime_error);
408✔
52

204✔
53
        case AutoClientResetFailed:
219✔
54
        case BadChangeset:
102✔
55
        case ConnectionClosed:
108✔
56
        case SubscriptionFailed:
114✔
57
        case SyncClientResetRequired:
123✔
58
        case SyncCompensatingWrite:
132✔
59
        case SyncPermissionDenied:
138✔
60
        case SyncProtocolInvariantFailed:
144✔
61
        case SyncServerPermissionsChanged:
150✔
62
        case SyncUserMismatch:
156✔
63
        case SyncWriteNotAllowed:
162✔
64
        case SyncLocalClockBeforeEpoch:
162✔
65
        case SyncSchemaMigrationError:
162✔
66
            return ErrorCategory().set(ErrorCategory::runtime_error).set(ErrorCategory::sync_error);
162✔
67

81✔
68
        case SyncConnectFailed:
87✔
69
        case SyncConnectTimeout:
36✔
70
        case SyncProtocolNegotiationFailed:
42✔
71
        case TlsHandshakeFailed:
48✔
72
            return ErrorCategory()
48✔
73
                .set(ErrorCategory::runtime_error)
48✔
74
                .set(ErrorCategory::websocket_error)
48✔
75
                .set(ErrorCategory::sync_error);
48✔
76

24✔
77
        case DecryptionFailed:
792✔
78
        case DeleteOnOpenRealm:
804✔
79
        case FileAlreadyExists:
894✔
80
        case FileFormatUpgradeRequired:
942✔
81
        case FileNotFound:
1,014✔
82
        case FileOperationFailed:
1,098✔
83
        case IncompatibleHistories:
1,122✔
84
        case IncompatibleLockFile:
1,152✔
85
        case IncompatibleSession:
1,164✔
86
        case InvalidDatabase:
1,380✔
87
        case PermissionDenied:
1,452✔
88
            return ErrorCategory().set(ErrorCategory::runtime_error).set(ErrorCategory::file_access);
1,452✔
89

690✔
90
        case SystemError:
714✔
91
            return ErrorCategory().set(ErrorCategory::runtime_error).set(ErrorCategory::system_error);
48✔
92

690✔
93
        case BrokenPromise:
4,803✔
94
        case ClosedRealm:
4,875✔
95
        case CrossTableLinkTarget:
4,890✔
96
        case IllegalOperation:
7,221✔
97
        case InvalidSchemaChange:
7,362✔
98
        case InvalidSchemaVersion:
7,377✔
99
        case InvalidTableRef:
7,404✔
100
        case InvalidatedObject:
8,430✔
101
        case KeyAlreadyUsed:
8,436✔
102
        case LogicError:
8,442✔
103
        case MigrationFailed:
8,463✔
104
        case MismatchedConfig:
8,478✔
105
        case NotSupported:
8,484✔
106
        case ReadOnlyDB:
8,493✔
107
        case SchemaMismatch:
8,625✔
108
        case SchemaValidationFailed:
8,859✔
109
        case SerializationError:
8,865✔
110
        case StaleAccessor:
8,982✔
111
        case WrongThread:
9,006✔
112
        case WrongTransactionState:
9,603✔
113
            return ErrorCategory().set(ErrorCategory::logic_error);
9,603✔
114

4,797✔
115
        case BadServerUrl:
7,434✔
116
        case IllegalCombination:
7,512✔
117
        case InvalidArgument:
8,370✔
118
        case InvalidDictionaryKey:
8,376✔
119
        case InvalidDictionaryValue:
8,388✔
120
        case InvalidEncryptionKey:
8,412✔
121
        case InvalidName:
8,460✔
122
        case InvalidProperty:
8,922✔
123
        case InvalidQuery:
10,749✔
124
        case InvalidQueryArg:
11,277✔
125
        case InvalidSortDescriptor:
11,307✔
126
        case KeyNotFound:
12,225✔
127
        case LimitExceeded:
12,243✔
128
        case MissingPrimaryKey:
12,258✔
129
        case MissingPropertyValue:
12,267✔
130
        case ModifyPrimaryKey:
12,279✔
131
        case NoSuchTable:
12,384✔
132
        case ObjectTypeMismatch:
12,528✔
133
        case OutOfBounds:
13,404✔
134
        case PropertyNotNullable:
13,542✔
135
        case ReadOnlyProperty:
13,551✔
136
        case SyntaxError:
14,679✔
137
        case TableNameInUse:
14,697✔
138
        case TopLevelObject:
14,703✔
139
        case TypeMismatch:
14,856✔
140
        case UnexpectedPrimaryKey:
14,874✔
141
            return ErrorCategory().set(ErrorCategory::invalid_argument).set(ErrorCategory::logic_error);
14,874✔
142

7,428✔
143
        case BadSyncPartitionValue:
7,434✔
144
        case InvalidSubscriptionQuery:
36✔
145
        case SyncInvalidSchemaChange:
42✔
146
        case WrongSyncType:
48✔
147
            return ErrorCategory()
48✔
148
                .set(ErrorCategory::invalid_argument)
48✔
149
                .set(ErrorCategory::logic_error)
48✔
150
                .set(ErrorCategory::sync_error);
48✔
151

24✔
152
        case CustomError:
114✔
153
            return ErrorCategory()
114✔
154
                .set(ErrorCategory::runtime_error)
114✔
155
                .set(ErrorCategory::app_error)
114✔
156
                .set(ErrorCategory::custom_error);
114✔
157

24✔
158
        case HTTPError:
486✔
159
            return ErrorCategory()
486✔
160
                .set(ErrorCategory::runtime_error)
486✔
161
                .set(ErrorCategory::app_error)
486✔
162
                .set(ErrorCategory::http_error);
486✔
163

24✔
164
        case ClientRedirectError:
117✔
165
        case ClientTooManyRedirects:
156✔
166
            return ErrorCategory()
156✔
167
                .set(ErrorCategory::runtime_error)
156✔
168
                .set(ErrorCategory::app_error)
156✔
169
                .set(ErrorCategory::client_error);
156✔
170

78✔
171
        case ClientUserNotFound:
108✔
172
        case ClientUserNotLoggedIn:
114✔
173
        case ClientUserAlreadyNamed:
123✔
174
            return ErrorCategory()
123✔
175
                .set(ErrorCategory::logic_error)
123✔
176
                .set(ErrorCategory::app_error)
123✔
177
                .set(ErrorCategory::client_error);
123✔
178

60✔
179
        case BadBsonParse:
144✔
180
        case BadToken:
189✔
181
        case MalformedJson:
213✔
182
        case MissingJsonKey:
222✔
183
            return ErrorCategory()
222✔
184
                .set(ErrorCategory::logic_error)
222✔
185
                .set(ErrorCategory::app_error)
222✔
186
                .set(ErrorCategory::json_error);
222✔
187

111✔
188
        case APIKeyAlreadyExists:
1,383✔
189
        case APIKeyNotFound:
1,524✔
190
        case AWSError:
1,533✔
191
        case AccountNameInUse:
1,548✔
192
        case AppServerError:
1,839✔
193
        case AppUnknownError:
2,007✔
194
        case ArgumentsNotAllowed:
2,016✔
195
        case AuthError:
2,028✔
196
        case AuthProviderAlreadyExists:
2,037✔
197
        case AuthProviderDuplicateName:
2,046✔
198
        case AuthProviderNotFound:
2,055✔
199
        case BadRequest:
2,094✔
200
        case DomainNotAllowed:
2,103✔
201
        case ExecutionTimeLimitExceeded:
2,112✔
202
        case FunctionAlreadyExists:
2,121✔
203
        case FunctionDuplicateName:
2,130✔
204
        case FunctionExecutionError:
2,139✔
205
        case FunctionInvalid:
2,148✔
206
        case FunctionNotFound:
2,157✔
207
        case FunctionSyntaxError:
2,166✔
208
        case GCMError:
2,175✔
209
        case IncomingWebhookAlreadyExists:
2,184✔
210
        case IncomingWebhookAuthFailed:
2,193✔
211
        case IncomingWebhookDuplicateName:
2,202✔
212
        case IncomingWebhookNotFound:
2,211✔
213
        case InternalServerError:
2,220✔
214
        case InvalidParameter:
2,241✔
215
        case InvalidPassword:
2,262✔
216
        case InvalidSession:
2,325✔
217
        case MaintenanceInProgress:
2,349✔
218
        case MissingAuthReq:
2,358✔
219
        case MissingParameter:
2,367✔
220
        case MongoDBError:
2,466✔
221
        case NoMatchingRuleFound:
2,475✔
222
        case NotCallable:
2,484✔
223
        case ReadSizeLimitExceeded:
2,493✔
224
        case RestrictedHost:
2,502✔
225
        case RuleAlreadyExists:
2,511✔
226
        case RuleDuplicateName:
2,520✔
227
        case RuleNotFound:
2,529✔
228
        case SchemaValidationFailedWrite:
2,574✔
229
        case ServiceAlreadyExists:
2,583✔
230
        case ServiceCommandNotFound:
2,592✔
231
        case ServiceNotFound:
2,613✔
232
        case ServiceTypeNotFound:
2,622✔
233
        case TwilioError:
2,631✔
234
        case UserAlreadyConfirmed:
2,652✔
235
        case UserAppDomainMismatch:
2,661✔
236
        case UserDisabled:
2,676✔
237
        case UserNotFound:
2,703✔
238
        case UserpassTokenInvalid:
2,712✔
239
        case InvalidServerResponse:
2,721✔
240
        case ValueAlreadyExists:
2,730✔
241
        case ValueDuplicateName:
2,739✔
242
        case ValueNotFound:
2,748✔
243
            return ErrorCategory()
2,748✔
244
                .set(ErrorCategory::runtime_error)
2,748✔
245
                .set(ErrorCategory::app_error)
2,748✔
246
                .set(ErrorCategory::service_error);
2,748✔
247

1,374✔
248
        case UnknownError:
1,374✔
UNCOV
249
            break;
×
UNCOV
250
    }
×
UNCOV
251
    return {};
×
UNCOV
252
}
×
253

254

255
struct MapElem {
256
    const char* name;
257
    ErrorCodes::Error code;
258
};
259

260
// Note: this array must be kept in sorted order
261
static const constexpr MapElem string_to_error_code[] = {
262
    {"APIKeyAlreadyExists", ErrorCodes::APIKeyAlreadyExists},
263
    {"APIKeyNotFound", ErrorCodes::APIKeyNotFound},
264
    {"AWSError", ErrorCodes::AWSError},
265
    {"AccountNameInUse", ErrorCodes::AccountNameInUse},
266
    {"AddressSpaceExhausted", ErrorCodes::AddressSpaceExhausted},
267
    {"AppServerError", ErrorCodes::AppServerError},
268
    {"AppUnknownError", ErrorCodes::AppUnknownError},
269
    {"ArgumentsNotAllowed", ErrorCodes::ArgumentsNotAllowed},
270
    {"AuthError", ErrorCodes::AuthError},
271
    {"AuthProviderAlreadyExists", ErrorCodes::AuthProviderAlreadyExists},
272
    {"AuthProviderDuplicateName", ErrorCodes::AuthProviderDuplicateName},
273
    {"AuthProviderNotFound", ErrorCodes::AuthProviderNotFound},
274
    {"AutoClientResetFailed", ErrorCodes::AutoClientResetFailed},
275
    {"BadBsonParse", ErrorCodes::BadBsonParse},
276
    {"BadChangeset", ErrorCodes::BadChangeset},
277
    {"BadRequest", ErrorCodes::BadRequest},
278
    {"BadServerUrl", ErrorCodes::BadServerUrl},
279
    {"BadSyncPartitionValue", ErrorCodes::BadSyncPartitionValue},
280
    {"BadToken", ErrorCodes::BadToken},
281
    {"BadVersion", ErrorCodes::BadVersion},
282
    {"BrokenInvariant", ErrorCodes::BrokenInvariant},
283
    {"BrokenPromise", ErrorCodes::BrokenPromise},
284
    {"CallbackFailed", ErrorCodes::CallbackFailed},
285
    {"ClientRedirectError", ErrorCodes::ClientRedirectError},
286
    {"ClientTooManyRedirects", ErrorCodes::ClientTooManyRedirects},
287
    {"ClientUserAlreadyNamed", ErrorCodes::ClientUserAlreadyNamed},
288
    {"ClientUserNotFound", ErrorCodes::ClientUserNotFound},
289
    {"ClientUserNotLoggedIn", ErrorCodes::ClientUserNotLoggedIn},
290
    {"ClosedRealm", ErrorCodes::ClosedRealm},
291
    {"ConnectionClosed", ErrorCodes::ConnectionClosed},
292
    {"CrossTableLinkTarget", ErrorCodes::CrossTableLinkTarget},
293
    {"CustomError", ErrorCodes::CustomError},
294
    {"DecryptionFailed", ErrorCodes::DecryptionFailed},
295
    {"DeleteOnOpenRealm", ErrorCodes::DeleteOnOpenRealm},
296
    {"DomainNotAllowed", ErrorCodes::DomainNotAllowed},
297
    {"ExecutionTimeLimitExceeded", ErrorCodes::ExecutionTimeLimitExceeded},
298
    {"FileAlreadyExists", ErrorCodes::FileAlreadyExists},
299
    {"FileFormatUpgradeRequired", ErrorCodes::FileFormatUpgradeRequired},
300
    {"FileNotFound", ErrorCodes::FileNotFound},
301
    {"FileOperationFailed", ErrorCodes::FileOperationFailed},
302
    {"FunctionAlreadyExists", ErrorCodes::FunctionAlreadyExists},
303
    {"FunctionDuplicateName", ErrorCodes::FunctionDuplicateName},
304
    {"FunctionExecutionError", ErrorCodes::FunctionExecutionError},
305
    {"FunctionInvalid", ErrorCodes::FunctionInvalid},
306
    {"FunctionNotFound", ErrorCodes::FunctionNotFound},
307
    {"FunctionSyntaxError", ErrorCodes::FunctionSyntaxError},
308
    {"GCMError", ErrorCodes::GCMError},
309
    {"HTTPError", ErrorCodes::HTTPError},
310
    {"IllegalOperation", ErrorCodes::IllegalOperation},
311
    {"IncomingWebhookAlreadyExists", ErrorCodes::IncomingWebhookAlreadyExists},
312
    {"IncomingWebhookAuthFailed", ErrorCodes::IncomingWebhookAuthFailed},
313
    {"IncomingWebhookDuplicateName", ErrorCodes::IncomingWebhookDuplicateName},
314
    {"IncomingWebhookNotFound", ErrorCodes::IncomingWebhookNotFound},
315
    {"IncompatibleHistories", ErrorCodes::IncompatibleHistories},
316
    {"IncompatibleLockFile", ErrorCodes::IncompatibleLockFile},
317
    {"IncompatibleSession", ErrorCodes::IncompatibleSession},
318
    {"InternalServerError", ErrorCodes::InternalServerError},
319
    {"InvalidArgument", ErrorCodes::InvalidArgument},
320
    {"InvalidCombination", ErrorCodes::IllegalCombination},
321
    {"InvalidDatabase", ErrorCodes::InvalidDatabase},
322
    {"InvalidDictionaryKey", ErrorCodes::InvalidDictionaryKey},
323
    {"InvalidDictionaryValue", ErrorCodes::InvalidDictionaryValue},
324
    {"InvalidEncryptionKey", ErrorCodes::InvalidEncryptionKey},
325
    {"InvalidName", ErrorCodes::InvalidName},
326
    {"InvalidParameter", ErrorCodes::InvalidParameter},
327
    {"InvalidPassword", ErrorCodes::InvalidPassword},
328
    {"InvalidProperty", ErrorCodes::InvalidProperty},
329
    {"InvalidQuery", ErrorCodes::InvalidQuery},
330
    {"InvalidQueryArg", ErrorCodes::InvalidQueryArg},
331
    {"InvalidSchemaChange", ErrorCodes::InvalidSchemaChange},
332
    {"InvalidSchemaVersion", ErrorCodes::InvalidSchemaVersion},
333
    {"InvalidServerResponse", ErrorCodes::InvalidServerResponse},
334
    {"InvalidSession", ErrorCodes::InvalidSession},
335
    {"InvalidSortDescriptor", ErrorCodes::InvalidSortDescriptor},
336
    {"InvalidSubscriptionQuery", ErrorCodes::InvalidSubscriptionQuery},
337
    {"InvalidTableRef", ErrorCodes::InvalidTableRef},
338
    {"InvalidatedObject", ErrorCodes::InvalidatedObject},
339
    {"KeyAlreadyUsed", ErrorCodes::KeyAlreadyUsed},
340
    {"KeyNotFound", ErrorCodes::KeyNotFound},
341
    {"LimitExceeded", ErrorCodes::LimitExceeded},
342
    {"LogicError", ErrorCodes::LogicError},
343
    {"MaintenanceInProgress", ErrorCodes::MaintenanceInProgress},
344
    {"MalformedJson", ErrorCodes::MalformedJson},
345
    {"MaximumFileSizeExceeded", ErrorCodes::MaximumFileSizeExceeded},
346
    {"MigrationFailed", ErrorCodes::MigrationFailed},
347
    {"MismatchedConfig", ErrorCodes::MismatchedConfig},
348
    {"MissingAuthReq", ErrorCodes::MissingAuthReq},
349
    {"MissingJsonKey", ErrorCodes::MissingJsonKey},
350
    {"MissingParameter", ErrorCodes::MissingParameter},
351
    {"MissingPrimaryKey", ErrorCodes::MissingPrimaryKey},
352
    {"MissingPropertyValue", ErrorCodes::MissingPropertyValue},
353
    {"ModifyPrimaryKey", ErrorCodes::ModifyPrimaryKey},
354
    {"MongoDBError", ErrorCodes::MongoDBError},
355
    {"MultipleSyncAgents", ErrorCodes::MultipleSyncAgents},
356
    {"NoMatchingRuleFound", ErrorCodes::NoMatchingRuleFound},
357
    {"NoSubscriptionForWrite", ErrorCodes::NoSubscriptionForWrite},
358
    {"NoSuchTable", ErrorCodes::NoSuchTable},
359
    {"NotCallable", ErrorCodes::NotCallable},
360
    {"NotCloneable", ErrorCodes::NotCloneable},
361
    {"NotSupported", ErrorCodes::NotSupported},
362
    {"OK", ErrorCodes::OK},
363
    {"ObjectAlreadyExists", ErrorCodes::ObjectAlreadyExists},
364
    {"ObjectTypeMismatch", ErrorCodes::ObjectTypeMismatch},
365
    {"OperationAborted", ErrorCodes::OperationAborted},
366
    {"OutOfBounds", ErrorCodes::OutOfBounds},
367
    {"OutOfDiskSpace", ErrorCodes::OutOfDiskSpace},
368
    {"OutOfMemory", ErrorCodes::OutOfMemory},
369
    {"PermissionDenied", ErrorCodes::PermissionDenied},
370
    {"PropertyNotNullable", ErrorCodes::PropertyNotNullable},
371
    {"RangeError", ErrorCodes::RangeError},
372
    {"ReadOnlyDB", ErrorCodes::ReadOnlyDB},
373
    {"ReadOnlyProperty", ErrorCodes::ReadOnlyProperty},
374
    {"ReadSizeLimitExceeded", ErrorCodes::ReadSizeLimitExceeded},
375
    {"RestrictedHost", ErrorCodes::RestrictedHost},
376
    {"RuleAlreadyExists", ErrorCodes::RuleAlreadyExists},
377
    {"RuleDuplicateName", ErrorCodes::RuleDuplicateName},
378
    {"RuleNotFound", ErrorCodes::RuleNotFound},
379
    {"RuntimeError", ErrorCodes::RuntimeError},
380
    {"SchemaMismatch", ErrorCodes::SchemaMismatch},
381
    {"SchemaValidationFailed", ErrorCodes::SchemaValidationFailed},
382
    {"SchemaValidationFailedWrite", ErrorCodes::SchemaValidationFailedWrite},
383
    {"SchemaVersionMismatch", ErrorCodes::SchemaVersionMismatch},
384
    {"SerializationError", ErrorCodes::SerializationError},
385
    {"ServiceAlreadyExists", ErrorCodes::ServiceAlreadyExists},
386
    {"ServiceCommandNotFound", ErrorCodes::ServiceCommandNotFound},
387
    {"ServiceNotFound", ErrorCodes::ServiceNotFound},
388
    {"ServiceTypeNotFound", ErrorCodes::ServiceTypeNotFound},
389
    {"StaleAccessor", ErrorCodes::StaleAccessor},
390
    {"SubscriptionFailed", ErrorCodes::SubscriptionFailed},
391
    {"SyncClientResetRequired", ErrorCodes::SyncClientResetRequired},
392
    {"SyncCompensatingWrite", ErrorCodes::SyncCompensatingWrite},
393
    {"SyncConnectFailed", ErrorCodes::SyncConnectFailed},
394
    {"SyncConnectTimeout", ErrorCodes::SyncConnectTimeout},
395
    {"SyncInvalidSchemaChange", ErrorCodes::SyncInvalidSchemaChange},
396
    {"SyncPermissionDenied", ErrorCodes::SyncPermissionDenied},
397
    {"SyncProtocolInvariantFailed", ErrorCodes::SyncProtocolInvariantFailed},
398
    {"SyncProtocolNegotiationFailed", ErrorCodes::SyncProtocolNegotiationFailed},
399
    {"SyncServerPermissionsChanged", ErrorCodes::SyncServerPermissionsChanged},
400
    {"SyncUserMismatch", ErrorCodes::SyncUserMismatch},
401
    {"SyncWriteNotAllowed", ErrorCodes::SyncWriteNotAllowed},
402
    {"SyntaxError", ErrorCodes::SyntaxError},
403
    {"SystemError", ErrorCodes::SystemError},
404
    {"TableNameInUse", ErrorCodes::TableNameInUse},
405
    {"TlsHandshakeFailed", ErrorCodes::TlsHandshakeFailed},
406
    {"TopLevelObject", ErrorCodes::TopLevelObject},
407
    {"TwilioError", ErrorCodes::TwilioError},
408
    {"TypeMismatch", ErrorCodes::TypeMismatch},
409
    {"UnexpectedPrimaryKey", ErrorCodes::UnexpectedPrimaryKey},
410
    {"UnsupportedFileFormatVersion", ErrorCodes::UnsupportedFileFormatVersion},
411
    {"UserAlreadyConfirmed", ErrorCodes::UserAlreadyConfirmed},
412
    {"UserAppDomainMismatch", ErrorCodes::UserAppDomainMismatch},
413
    {"UserDisabled", ErrorCodes::UserDisabled},
414
    {"UserNotFound", ErrorCodes::UserNotFound},
415
    {"UserpassTokenInvalid", ErrorCodes::UserpassTokenInvalid},
416
    {"ValueAlreadyExists", ErrorCodes::ValueAlreadyExists},
417
    {"ValueDuplicateName", ErrorCodes::ValueDuplicateName},
418
    {"ValueNotFound", ErrorCodes::ValueNotFound},
419
    {"WrongSyncType", ErrorCodes::WrongSyncType},
420
    {"WrongThread", ErrorCodes::WrongThread},
421
    {"WrongTransactionState", ErrorCodes::WrongTransactionState},
422
};
423

424
namespace {
425

426
class ErrorCodesMap {
427
public:
428
    ErrorCodesMap()
429
    {
24✔
430
#if REALM_DEBUG
24✔
431
        bool is_valid =
24✔
432
            std::is_sorted(std::begin(string_to_error_code), std::end(string_to_error_code), [](auto& a, auto& b) {
3,816✔
433
                if (strcmp(a.name, b.name) < 0) {
3,816✔
UNCOV
434
                    std::cout << a.name << " comes before " << b.name << std::endl;
×
UNCOV
435
                    return true;
×
UNCOV
436
                }
×
437
                return false;
3,816✔
438
            });
3,816✔
439

12✔
440
        REALM_ASSERT_DEBUG(is_valid);
24✔
441
#endif
24✔
442
    }
24✔
443

444
    ErrorCodes::Error operator[](std::string_view name)
445
    {
3,288✔
446
        auto it = std::lower_bound(std::begin(string_to_error_code), std::end(string_to_error_code), name,
3,288✔
447
                                   [](auto& ec_pair, auto name) {
24,468✔
448
                                       return strncmp(ec_pair.name, name.data(), name.size()) < 0;
24,468✔
449
                                   });
24,468✔
450
        if (it != std::end(string_to_error_code) && it->name == name) {
3,288✔
451
            return it->code;
3,264✔
452
        }
3,264✔
453
        return ErrorCodes::UnknownError;
24✔
454
    }
24✔
455

456
    std::string_view operator[](ErrorCodes::Error code)
457
    {
4,689✔
458
        for (auto [name, c] : string_to_error_code) {
306,261✔
459
            if (code == c) {
306,261✔
460
                return name;
4,683✔
461
            }
4,683✔
462
        }
306,261✔
463
        return "unknown";
2,436✔
464
    }
4,689✔
465
} error_codes_map;
466

467
} // namespace
468

469
std::string_view ErrorCodes::error_string(Error code)
470
{
4,689✔
471
    return error_codes_map[code];
4,689✔
472
}
4,689✔
473

474
ErrorCodes::Error ErrorCodes::from_string(std::string_view name)
475
{
3,288✔
476
    return error_codes_map[name];
3,288✔
477
}
3,288✔
478

479
std::vector<ErrorCodes::Error> ErrorCodes::get_all_codes()
480
{
6✔
481
    std::vector<ErrorCodes::Error> ret;
6✔
482
    for (auto it : string_to_error_code) {
960✔
483
        ret.push_back(it.code);
960✔
484
    }
960✔
485
    return ret;
6✔
486
}
6✔
487

488
std::vector<std::string_view> ErrorCodes::get_all_names()
489
{
6✔
490
    std::vector<std::string_view> ret;
6✔
491
    for (auto it : string_to_error_code) {
960✔
492
        ret.emplace_back(it.name);
960✔
493
    }
960✔
494
    return ret;
6✔
495
}
6✔
496

497
std::vector<std::pair<std::string_view, ErrorCodes::Error>> ErrorCodes::get_error_list()
498
{
6✔
499
    std::vector<std::pair<std::string_view, ErrorCodes::Error>> ret;
6✔
500
    for (auto it : string_to_error_code) {
960✔
501
        ret.emplace_back(std::make_pair(it.name, it.code));
960✔
502
    }
960✔
503
    return ret;
6✔
504
}
6✔
505

506
std::ostream& operator<<(std::ostream& stream, ErrorCodes::Error code)
UNCOV
507
{
×
UNCOV
508
    return stream << ErrorCodes::error_string(code);
×
UNCOV
509
}
×
510

511

512
} // namespace realm
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc