realm-js
realm-js copied to clipboard
Error Realm initialization with sync enabled due to mismatch schema is not calling onError function
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
- Create a sample app
- Set to open the realm for the first time DownloadBeforeOpen
- Change the schema to a breaking schema
- delete the local realm
- Open the app again and see that the error is only printed at the console
Version
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
➤ PM Bot commented:
Jira ticket: RJS-2794
@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).
We agree an error like this should signaled differently than calling console.error
:
- Calling
onError
would be difficult, because that function takes the active sync session, but at this point no sync session has been established. To call it, we would have to break the API, allowing theonError
to havenull
passed as the sync session argument, which is not ideal. So .. since this error isn't sync specific, we would most likely want to surface it differently than though theonError
. - The
RealmProvider
could take anonError
prop (admittedly, this name might be a little confusing as it conflicts with theonError
passed through thesync
config). - We could throw when the
useRealm
(or any of our other hooks depending on it). - Some other alternative that we haven't thought of? What's an idiomatic way to signal an error state from a React context provider? 🤔