realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.6k stars 558 forks source link

Error Realm initialization with sync enabled due to mismatch schema is not calling onError function #6601

Open gfrancischini opened 3 weeks ago

gfrancischini commented 3 weeks ago

How frequently does the bug occur?

Always

Description

Check the following line:

https://github.com/realm/realm-js/blob/91de9446242a3dc7aaaf640925af360b5d91a7d2/packages/realm-react/src/RealmProvider.tsx#L140

It is calling the console.error directly. This way we cannot handle this error on user device.

We have configured the application to only open the realm for the first time after DownloadBeforeOpen.

Stacktrace & log output

[Error: The following changes cannot be made in additive-only schema mode:
- Property 'ObjectType.idInitialStatusIntegration' has been made required.
- Property 'ObjectType.idInitialStatusPDA' has been made required.
- Property 'ObjectType.idInitialStatusWeb' has been made required.
- Property 'ObjectType.nmCdField' has been made required.
- Property 'ObjectType.nmDisplayField' has been made required.
- Property 'ObjectType.nmIdField' has been made required.
- Property 'ObjectType.nmTable' has been made required.
If your app is running in development mode, you can delete the realm and restart the app to update your schema.]

Can you reproduce the bug?

Always

Reproduction Steps

  1. Create a sample app
  2. Set to open the realm for the first time DownloadBeforeOpen
  3. Change the schema to a breaking schema
  4. delete the local realm
  5. Open the app again and see that the error is only printed at the console

Version

realm@12.6.2

What services are you using?

Atlas Device Sync

Are you using encryption?

No

Platform OS and version(s)

Android/iOS All

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

sync-by-unito[bot] commented 3 weeks ago

➤ PM Bot commented:

Jira ticket: RJS-2794

kneth commented 2 weeks ago

@gfrancischini Thank you for reporting.

I believe that we should extend @realm/react with an option not to shallow the exceptions from Realm.open(). We can either rethrow the exception or call the onError callback (if defined).