From 02cb2fc51d1c07cdbabc2f5e5b2dbe22fa762d28 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Thu, 1 Dec 2022 00:57:15 +0200 Subject: [PATCH 1/6] Set missing SyncError codes to Unknown --- CHANGELOG.md | 1 + common/lib/src/realm_types.dart | 33 +++++++++++----------------- lib/src/configuration.dart | 38 ++++++++++++++------------------- 3 files changed, 29 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbf65c57b..b18aa887f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) +* If `syncErrorHandler` occurs with a new unknown error code then return `SyncSessionErrorCode.unknown`, `SyncConnectionErrorCode.unknown`, `SyncClientErrorCode.unknown` or `GeneralSyncErrorCode.unknown` instead of throwing exception. ### Fixed * Support mapping into `SyncSessionErrorCode` for "Compensating write" with error code 231. ([#1022](https://github.com/realm/realm-dart/pull/1022)) diff --git a/common/lib/src/realm_types.dart b/common/lib/src/realm_types.dart index 07435e0d8..31f720c76 100644 --- a/common/lib/src/realm_types.dart +++ b/common/lib/src/realm_types.dart @@ -250,17 +250,14 @@ enum SyncClientErrorCode { httpTunnelFailed(131), /// A fatal error was encountered which prevents completion of a client reset - autoClientResetFailure(132); + autoClientResetFailure(132), + + unknown(9999); static final Map _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; @@ -316,17 +313,14 @@ enum SyncConnectionErrorCode { switchToFlxSync(113), /// Connected with wrong wire protocol - should switch to PBS - switchToPbs(114); + switchToPbs(114), + + unknown(9999); static final Map _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; @@ -430,17 +424,14 @@ 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(9999); static final Map _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; diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index a46d00f5e..ab8865884 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -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)); @@ -228,7 +228,7 @@ abstract class Configuration implements Finalizable { path: path, fifoFilesFallbackPath: fifoFilesFallbackPath, encryptionKey: encryptionKey, - maxNumberOfActiveVersions: maxNumberOfActiveVersions + maxNumberOfActiveVersions: maxNumberOfActiveVersions, ); void _validateEncryptionKey(List? key) { @@ -252,20 +252,19 @@ abstract class Configuration implements Finalizable { /// that are persisted across runs. /// {@category Configuration} class LocalConfiguration extends Configuration { - LocalConfiguration._( - super.schemaObjects, { - this.initialDataCallback, - this.schemaVersion = 0, - super.fifoFilesFallbackPath, - super.path, - super.encryptionKey, - this.disableFormatUpgrade = false, - this.isReadOnly = false, - this.shouldCompactCallback, - this.migrationCallback, - super.maxNumberOfActiveVersions, - this.shouldDeleteIfMigrationNeeded = false - }) : super._(); + LocalConfiguration._(super.schemaObjects, + {this.initialDataCallback, + this.schemaVersion = 0, + super.fifoFilesFallbackPath, + super.path, + super.encryptionKey, + this.disableFormatUpgrade = false, + this.isReadOnly = false, + this.shouldCompactCallback, + this.migrationCallback, + super.maxNumberOfActiveVersions, + this.shouldDeleteIfMigrationNeeded = false}) + : super._(); /// The schema version used to open the `Realm`. If omitted, the default value is `0`. /// @@ -749,12 +748,7 @@ enum GeneralSyncErrorCode { static final Map _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; From f8aad9b4b40f2b7b4fc5b038e20b468277eda0f1 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Thu, 1 Dec 2022 00:59:13 +0200 Subject: [PATCH 2/6] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b18aa887f..d4044c6a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +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)) -* If `syncErrorHandler` occurs with a new unknown error code then return `SyncSessionErrorCode.unknown`, `SyncConnectionErrorCode.unknown`, `SyncClientErrorCode.unknown` or `GeneralSyncErrorCode.unknown` instead of throwing exception. +* If `syncErrorHandler` occurs with a new unknown error code then return `SyncSessionErrorCode.unknown`, `SyncConnectionErrorCode.unknown`, `SyncClientErrorCode.unknown` or `GeneralSyncErrorCode.unknown` instead of throwing exception. ([#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)) From 1cb1e11be975aa7328c607e83848539543f4f7e3 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova <95419820+desistefanova@users.noreply.github.com> Date: Thu, 1 Dec 2022 12:46:11 +0200 Subject: [PATCH 3/6] Update CHANGELOG.md Co-authored-by: blagoev --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4044c6a1..63e907c8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +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)) -* If `syncErrorHandler` occurs with a new unknown error code then return `SyncSessionErrorCode.unknown`, `SyncConnectionErrorCode.unknown`, `SyncClientErrorCode.unknown` or `GeneralSyncErrorCode.unknown` instead of throwing exception. ([#1052](https://github.com/realm/realm-dart/pull/1052)) +* Add `unknown` error code to all SyncErrors. `SyncSessionErrorCode.unknown`, `SyncConnectionErrorCode.unknown`, `SyncClientErrorCode.unknown` or `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)) From 17d448ede9cd37450e96559d7ca73405bb56fd60 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Thu, 1 Dec 2022 12:54:18 +0200 Subject: [PATCH 4/6] Code review changes --- common/lib/src/realm_types.dart | 3 +++ lib/src/configuration.dart | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/common/lib/src/realm_types.dart b/common/lib/src/realm_types.dart index 31f720c76..639f86e81 100644 --- a/common/lib/src/realm_types.dart +++ b/common/lib/src/realm_types.dart @@ -252,6 +252,7 @@ enum SyncClientErrorCode { /// A fatal error was encountered which prevents completion of a client reset autoClientResetFailure(132), + /// Unknown error code unknown(9999); static final Map _valuesMap = {for (var value in SyncClientErrorCode.values) value.code: value}; @@ -315,6 +316,7 @@ enum SyncConnectionErrorCode { /// Connected with wrong wire protocol - should switch to PBS switchToPbs(114), + /// Unknown error code unknown(9999); static final Map _valuesMap = {for (var value in SyncConnectionErrorCode.values) value.code: value}; @@ -426,6 +428,7 @@ enum SyncSessionErrorCode { /// outside the current query, and the server undid the modification (UPLOAD) compensatingWrite(231), + /// Unknown error code unknown(9999); static final Map _valuesMap = {for (var value in SyncSessionErrorCode.values) value.code: value}; diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index ab8865884..871ebe57d 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -252,19 +252,20 @@ abstract class Configuration implements Finalizable { /// that are persisted across runs. /// {@category Configuration} class LocalConfiguration extends Configuration { - LocalConfiguration._(super.schemaObjects, - {this.initialDataCallback, - this.schemaVersion = 0, - super.fifoFilesFallbackPath, - super.path, - super.encryptionKey, - this.disableFormatUpgrade = false, - this.isReadOnly = false, - this.shouldCompactCallback, - this.migrationCallback, - super.maxNumberOfActiveVersions, - this.shouldDeleteIfMigrationNeeded = false}) - : super._(); + LocalConfiguration._( + super.schemaObjects, { + this.initialDataCallback, + this.schemaVersion = 0, + super.fifoFilesFallbackPath, + super.path, + super.encryptionKey, + this.disableFormatUpgrade = false, + this.isReadOnly = false, + this.shouldCompactCallback, + this.migrationCallback, + super.maxNumberOfActiveVersions, + this.shouldDeleteIfMigrationNeeded = false, + }) : super._(); /// The schema version used to open the `Realm`. If omitted, the default value is `0`. /// @@ -742,7 +743,7 @@ class GeneralSyncError extends SyncError { /// General sync error codes enum GeneralSyncErrorCode { - // A general sync error code + /// Unknown error code unknown(9999); static final Map _valuesMap = {for (var value in GeneralSyncErrorCode.values) value.code: value}; From 568659566d7ec4049a1368c7a7783ed4fb199c35 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Thu, 1 Dec 2022 12:56:41 +0200 Subject: [PATCH 5/6] Fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63e907c8d..490001659 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +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` or `GeneralSyncErrorCode.unknown`. Use `unknown` error code instead of throwing a RealmError. ([#1052](https://github.com/realm/realm-dart/pull/1052)) +* 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)) From dd918416bb7183c6206297b0c19a7027113d222d Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Fri, 2 Dec 2022 10:59:52 +0200 Subject: [PATCH 6/6] Change API doc --- common/lib/src/realm_types.dart | 6 +++--- lib/src/configuration.dart | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/lib/src/realm_types.dart b/common/lib/src/realm_types.dart index 639f86e81..98326b342 100644 --- a/common/lib/src/realm_types.dart +++ b/common/lib/src/realm_types.dart @@ -252,7 +252,7 @@ enum SyncClientErrorCode { /// A fatal error was encountered which prevents completion of a client reset autoClientResetFailure(132), - /// Unknown error code + /// Unknown Sync client error code unknown(9999); static final Map _valuesMap = {for (var value in SyncClientErrorCode.values) value.code: value}; @@ -316,7 +316,7 @@ enum SyncConnectionErrorCode { /// Connected with wrong wire protocol - should switch to PBS switchToPbs(114), - /// Unknown error code + /// Unknown Sync connection error code unknown(9999); static final Map _valuesMap = {for (var value in SyncConnectionErrorCode.values) value.code: value}; @@ -428,7 +428,7 @@ enum SyncSessionErrorCode { /// outside the current query, and the server undid the modification (UPLOAD) compensatingWrite(231), - /// Unknown error code + /// Unknown Sync session error code unknown(9999); static final Map _valuesMap = {for (var value in SyncSessionErrorCode.values) value.code: value}; diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index 871ebe57d..b54cc1db3 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -743,7 +743,7 @@ class GeneralSyncError extends SyncError { /// General sync error codes enum GeneralSyncErrorCode { - /// Unknown error code + /// Unknown Sync error code unknown(9999); static final Map _valuesMap = {for (var value in GeneralSyncErrorCode.values) value.code: value};