Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-732

Creating directly embedded objects segfaults instead of throwing an exception

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • JS-10.0.0-beta.10
    • Affects Version/s: None
    • Component/s: None
    • None

      The Node SDK segfaults rather than throwing a useful/catchable error if you try to create an embedded object directly rather than from a parent object.

      const Realm = require("realm");
      const config = {
        path: "embeddedObjects",
        schema: [{
          name: "Address",
          embedded: true,
          properties: {
            street: "string",
            city: "string"
          },
        }, {
          name: "Contact",
          properties: {
            name: "string",
            address: "Address",
          },
        }],
      }
      async function main() {
        Realm.deleteFile(config)
        const realm = await Realm.open(config);
        // This write succeeds, as expected!
        realm.write(() => {
          realm.create("Contact", {
            name: "Joe Jasper",
            address: { street: "123 Main Street", city: "New York City" }
          })
        })
        // This write throws a useful error: "Error: Object type 'Foo' not found in schema.""
        realm.write(() => {
          realm.create("Foo", { bar: 42 })
        })
        // Address is an embedded object type, so this write should not work.
        // However, the call segfaults rather than throwing a useful error.
        // e.g. "Error: Object type 'Address' is embeddable, so it cannot be directly created."
        realm.write(() => {
          realm.create("Address", {
            street: "123 Main Street", city: "New York City"
          })
        })
        realm.close()
        return process.exit()
      }
      main().catch(err => {
        console.error(err)
      })
      

            Assignee:
            franck.franck@mongodb.com Franck Franck (Inactive)
            Reporter:
            lubo.blagoev@mongodb.com Lubo Blagoev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: