Skip to content

Commit

Permalink
Map is_fatal to UnrecoverableSyncException
Browse files Browse the repository at this point in the history
  • Loading branch information
clementetb committed May 29, 2024
1 parent e8949fe commit 3f3aff3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This release will bump the Realm file format 24. Opening a file with an older fo
* Inserting the same typed link to the same key in a dictionary more than once would incorrectly create multiple backlinks to the object. This did not appear to cause any crashes later, but would have affecting explicit backlink count queries (eg: `...@links.@count`) and possibly notifications (Core Issue [realm/realm-core#7676](https://github.com/realm/realm-core/issues/7676) since v1.16.0).
* [Sync] Automatic client reset recovery would crash when recovering AddInteger instructions on a Mixed property if its type was changed to non-integer (Core issue [realm/realm-core#7683](https://github.com/realm/realm-core/pull/7683), since v0.11.0).
* [Sync] Typos [SubscriptionSetState.SUPERSEDED], [SyncTimeoutOptions.pingKeepalivePeriod] and [SyncTimeoutOptions.pongKeepalivePeriod]. (Issue [#1754](https://github.com/realm/realm-kotlin/pull/1754)
* [Sync] Fatal sync exceptions are now thrown as `UnrecoverableSyncException`. (Issue [#1767](https://github.com/realm/realm-kotlin/issues/1767) [RKOTLIN-1096](https://jira.mongodb.org/browse/RKOTLIN-1096)).

### Compatibility
* File format: Generates Realms with file format v24 (reads and upgrades file format v10 or later).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,27 @@ internal fun <T, R> channelResultCallback(
internal fun convertSyncError(syncError: SyncError): SyncException {
val errorCode = syncError.errorCode
val message = createMessageFromSyncError(errorCode)
return when (errorCode.errorCode) {
ErrorCode.RLM_ERR_WRONG_SYNC_TYPE -> WrongSyncTypeException(message)
return if (syncError.isFatal) {
// An unrecoverable exception happened
UnrecoverableSyncException(message)
} else {
when (errorCode.errorCode) {
ErrorCode.RLM_ERR_WRONG_SYNC_TYPE -> WrongSyncTypeException(message)

ErrorCode.RLM_ERR_INVALID_SUBSCRIPTION_QUERY -> {
// Flexible Sync Query was rejected by the server
BadFlexibleSyncQueryException(message)
}
ErrorCode.RLM_ERR_SYNC_COMPENSATING_WRITE -> CompensatingWriteException(message, syncError.compensatingWrites)
ErrorCode.RLM_ERR_INVALID_SUBSCRIPTION_QUERY -> {
// Flexible Sync Query was rejected by the server
BadFlexibleSyncQueryException(message)
}

ErrorCode.RLM_ERR_SYNC_PROTOCOL_INVARIANT_FAILED,
ErrorCode.RLM_ERR_SYNC_PROTOCOL_NEGOTIATION_FAILED,
ErrorCode.RLM_ERR_SYNC_PERMISSION_DENIED -> {
// Permission denied errors should be unrecoverable according to Core, i.e. the
// client will disconnect sync and transition to the "inactive" state
UnrecoverableSyncException(message)
}
else -> {
// An error happened we are not sure how to handle. Just report as a generic
// SyncException.
SyncException(message)
ErrorCode.RLM_ERR_SYNC_COMPENSATING_WRITE -> CompensatingWriteException(
message,
syncError.compensatingWrites
)
else -> {
// An error happened we are not sure how to handle. Just report as a generic
// SyncException.
SyncException(message)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import io.realm.kotlin.mongodb.App
import io.realm.kotlin.mongodb.User
import io.realm.kotlin.mongodb.exceptions.DownloadingRealmTimeOutException
import io.realm.kotlin.mongodb.exceptions.SyncException
import io.realm.kotlin.mongodb.exceptions.UnrecoverableSyncException
import io.realm.kotlin.mongodb.subscriptions
import io.realm.kotlin.mongodb.sync.InitialSubscriptionsCallback
import io.realm.kotlin.mongodb.sync.SubscriptionSetState
Expand Down Expand Up @@ -336,13 +335,12 @@ class SyncedRealmTests {
Realm.open(config).use {
// Make sure that the test eventually fail. Coroutines can cancel a delay
// so this doesn't always block the test for 10 seconds.
delay(10 * 1000)
delay(10_000)
channel.send(AssertionError("Realm was successfully opened"))
}
}

val error = channel.receiveOrFail()
assertTrue(error is UnrecoverableSyncException, "Was $error")
val message = error.message
assertNotNull(message)
assertTrue(
Expand Down

0 comments on commit 3f3aff3

Please sign in to comment.