realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

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

Open gfrancischini opened this issue 4 months ago • 9 comments

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

[email protected]

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

gfrancischini avatar Apr 08 '24 11:04 gfrancischini

➤ PM Bot commented:

Jira ticket: RJS-2794

sync-by-unito[bot] avatar Apr 08 '24 11:04 sync-by-unito[bot]

@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).

kneth avatar Apr 09 '24 07:04 kneth

We agree an error like this should signaled differently than calling console.error:

  1. 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 the onError to have null 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 the onError.
  2. The RealmProvider could take an onError prop (admittedly, this name might be a little confusing as it conflicts with the onError passed through the sync config).
  3. We could throw when the useRealm (or any of our other hooks depending on it).
  4. Some other alternative that we haven't thought of? What's an idiomatic way to signal an error state from a React context provider? 🤔

kraenhansen avatar May 08 '24 12:05 kraenhansen