Thank you for the detailed question. This allows me to give you a proper answer.
- As I understood correctly the session errors are related to the cloud realm synchronization. The realm errors are related to the local database and emit when managing it (read/write). Please correct me if I’m wrong.
You’re correct. The errors in Realms.Exceptions
pertain to the local database and in almost all cases indicate a developer error. You should rarely see them in the wild and if you do, it’s best to send an automatic error report and fix the bug in the code.
Now, going to the part you’re mostly interested in: Realm Sync and the error handling of it.
The sync errors are going to be communicated via a SessionException and its subclasses.
The unrecoverable errors are ClientResetException
and PermissionDeniedException
- if the user encounters those, it’s typically most prudent to redirect them to a splash screen notifying them that such an error occurred, delete the offending local Realm file, then reinitialize the application. If the error persists, such as if there’s a diverging schema between the local and server database, you should instruct the user to download the latest version of the app or contact you.
On the other hand, sync errors that are not client reset or permission denied are recoverable and Realm will automatically reconnect after a retry. You may want to tell the user that sync is temporarily paused and will resume shortly. It may be prudent to automatically log such errors though and monitor their occurrence over time - if they suddenly start happening more often than before or affecting many users, you should investigate.
On the last part, “prevention of data loss” is a complicated matter. It requires a very laborious process of diffing the content of the downloaded realm with the local one. At that point what’s only on the local realm needs to be inserted in the downloaded one.
We realize that this process is complicated and error prone, so we’re working hard, as we speak, on automating this whole process. Unfortunately, we don’t have a timeline for release yet; therefore keep following our releases and announcements.
I hope I have given you all the information that you needed.