Uploaded image for project: 'Realm Kotlin'
  1. Realm Kotlin
  2. RKOTLIN-1090

RLM_ERR_UNSUPPORTED_FILE_FORMAT_VERSION should throw a specific exception, not just IllegalStateException

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None

      Problem

      I have an app that is using local realms. It does happen that users take a break from the app and then come back. When dropping support for pre Realm 5.0.0 files, those users are out of luck. I know you can't bring backwards compatibility back, but right now it is not possible to detect that this error has happened on the Kotlin client whereas on iOS realm throws a specific error (Realm.Error.unsupportedFileFormatVersion) that at least allows developers to catch the error and provide a way for the user to reach out to support (or send the file to a server to convert it as suggested by @nirinchev in another github issue).

      Solution

      Right now this is all I can do is to check if we get an IllegalStateException then inspect the message to see if it is an unsupported file format version error. This is NOT something that should have to go into production code IMHO.

      try {
           val realm = Realm.open(configuration)
      } catch (error:Exception){
          if(error is IllegalStateException && error.message?.contains("RLM_ERR_UNSUPPORTED_FILE_FORMAT_VERSION") == true){
              //Show dialog to reach out to support or use server function to upgrade database
          }
      }
      

      Does the current API let me detect this in any other way? Is it safe to use this hack? Or are my returning customers screwed?

      Alternatives

      No response

      How important is this improvement for you?

      Dealbreaker

      Feature would mainly be used with

      Local Database only

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: