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

RLM_ERR_UNSUPPORTED_FILE_FORMAT_VERSION should throw a specific exception, not just IllegalStateException #1761

Open
sipersso opened this issue May 22, 2024 · 4 comments

Comments

@sipersso
Copy link

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

Copy link

sync-by-unito bot commented May 22, 2024

➤ PM Bot commented:

Jira ticket: RKOTLIN-1090

@kneth
Copy link
Member

kneth commented May 23, 2024

Currently there is not elegant way to detect it. We could expose this Realm Core function.

@nirinchev
Copy link
Member

Why can't we detect it? As far as I can tell, we have an error code for it: https://github.com/realm/realm-core/blob/3648014ffdcaf6f570de78e1cb4572300c217975/src/realm/error_codes.h#L51

So it should be a matter of switching on the error code and throwing a more concrete exception.

@sipersso
Copy link
Author

Why can't we detect it? As far as I can tell, we have an error code for it: https://github.com/realm/realm-core/blob/3648014ffdcaf6f570de78e1cb4572300c217975/src/realm/error_codes.h#L51

So it should be a matter of switching on the error code and throwing a more concrete exception.

This would be the way to go IMHO. You can still use IllegalStateException if you just create a subclass that represents this specific error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants