Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set missing SyncError codes to Unknown #1052

Merged
merged 7 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Support setting `maxNumberOfActiveVersions` when creating a `Configuration`. ([#1036](https://github.com/realm/realm-dart/pull/1036))
* Add List.move extension method that moves an element from one index to another. Delegates to ManagedRealmList.move for managed lists. This allows notifications to correctly report moves, as opposed to reporting moves as deletes + inserts. ([#1037](https://github.com/realm/realm-dart/issues/1037))
* Support setting `shouldDeleteIfMigrationNeeded` when creating a `Configuration.local`. ([#1049](https://github.com/realm/realm-dart/issues/1049))
* Add `unknown` error code to all SyncErrors: `SyncSessionErrorCode.unknown`, `SyncConnectionErrorCode.unknown`, `SyncClientErrorCode.unknown`, `GeneralSyncErrorCode.unknown`. Use `unknown` error code instead of throwing a RealmError. ([#1052](https://github.com/realm/realm-dart/pull/1052))

### Fixed
* Support mapping into `SyncSessionErrorCode` for "Compensating write" with error code 231. ([#1022](https://github.com/realm/realm-dart/pull/1022))
Expand Down
36 changes: 15 additions & 21 deletions common/lib/src/realm_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,15 @@ enum SyncClientErrorCode {
httpTunnelFailed(131),

/// A fatal error was encountered which prevents completion of a client reset
autoClientResetFailure(132);
autoClientResetFailure(132),

/// Unknown Sync client error code
unknown(9999);

static final Map<int, SyncClientErrorCode> _valuesMap = {for (var value in SyncClientErrorCode.values) value.code: value};

static SyncClientErrorCode fromInt(int code) {
final mappedCode = SyncClientErrorCode._valuesMap[code];
if (mappedCode == null) {
throw RealmError("Unknown SyncClientErrorCode");
}

return mappedCode;
return SyncClientErrorCode._valuesMap[code] ?? SyncClientErrorCode.unknown;
}

final int code;
Expand Down Expand Up @@ -316,17 +314,15 @@ enum SyncConnectionErrorCode {
switchToFlxSync(113),

/// Connected with wrong wire protocol - should switch to PBS
switchToPbs(114);
switchToPbs(114),

/// Unknown Sync connection error code
unknown(9999);
desistefanova marked this conversation as resolved.
Show resolved Hide resolved

static final Map<int, SyncConnectionErrorCode> _valuesMap = {for (var value in SyncConnectionErrorCode.values) value.code: value};

static SyncConnectionErrorCode fromInt(int code) {
final mappedCode = SyncConnectionErrorCode._valuesMap[code];
if (mappedCode == null) {
throw RealmError("Unknown SyncConnectionErrorCode");
}

return mappedCode;
return SyncConnectionErrorCode._valuesMap[code] ?? SyncConnectionErrorCode.unknown;
}

final int code;
Expand Down Expand Up @@ -430,17 +426,15 @@ enum SyncSessionErrorCode {

/// Client attempted a write that is disallowed by permissions, or modifies an object
/// outside the current query, and the server undid the modification (UPLOAD)
compensatingWrite(231);
compensatingWrite(231),

/// Unknown Sync session error code
unknown(9999);

static final Map<int, SyncSessionErrorCode> _valuesMap = {for (var value in SyncSessionErrorCode.values) value.code: value};

static SyncSessionErrorCode fromInt(int code) {
final mappedCode = SyncSessionErrorCode._valuesMap[code];
if (mappedCode == null) {
throw RealmError("Unknown SyncSessionErrorCode");
}

return mappedCode;
return SyncSessionErrorCode._valuesMap[code] ?? SyncSessionErrorCode.unknown;
}

final int code;
Expand Down
15 changes: 5 additions & 10 deletions lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ abstract class Configuration implements Finalizable {
String? path,
this.fifoFilesFallbackPath,
this.encryptionKey,
this.maxNumberOfActiveVersions
this.maxNumberOfActiveVersions,
}) {
_validateEncryptionKey(encryptionKey);
this.path = path ?? _path.join(_path.dirname(_defaultPath), _path.basename(defaultRealmName));
Expand Down Expand Up @@ -228,7 +228,7 @@ abstract class Configuration implements Finalizable {
path: path,
fifoFilesFallbackPath: fifoFilesFallbackPath,
encryptionKey: encryptionKey,
maxNumberOfActiveVersions: maxNumberOfActiveVersions
maxNumberOfActiveVersions: maxNumberOfActiveVersions,
);

void _validateEncryptionKey(List<int>? key) {
Expand Down Expand Up @@ -264,7 +264,7 @@ class LocalConfiguration extends Configuration {
this.shouldCompactCallback,
this.migrationCallback,
super.maxNumberOfActiveVersions,
this.shouldDeleteIfMigrationNeeded = false
this.shouldDeleteIfMigrationNeeded = false,
}) : super._();

/// The schema version used to open the `Realm`. If omitted, the default value is `0`.
Expand Down Expand Up @@ -743,18 +743,13 @@ class GeneralSyncError extends SyncError {

/// General sync error codes
enum GeneralSyncErrorCode {
// A general sync error code
/// Unknown Sync error code
unknown(9999);

static final Map<int, GeneralSyncErrorCode> _valuesMap = {for (var value in GeneralSyncErrorCode.values) value.code: value};

static GeneralSyncErrorCode fromInt(int code) {
final mappedCode = GeneralSyncErrorCode._valuesMap[code];
if (mappedCode == null) {
throw RealmError("Unknown GeneralSyncErrorCode");
}

return mappedCode;
return GeneralSyncErrorCode._valuesMap[code] ?? GeneralSyncErrorCode.unknown;
}

final int code;
Expand Down