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

Write transaction's exceptions are not being caught by try catch block

      How frequently does the bug occur?

      All the time

      Description

      Exceptions are not being caught!!!

      let realm;
      let response;
      try {
      realm = options.realm || await Realm.open(db);
      realm.beginTransaction();

          response = await getCustomer({ id: payload.id }, { realm: realm })
          if (response) {
              response.date_updated = Date.now();
              if (payload.name) {
                  response.name = payload?.name;
              }
              if (payload.email) {
                  response.email = payload?.email;
              }
              if (Array.isArray(payload.tags)) {
                  response.tags = payload.tags;
              }
              if (payload.address) {
                  response.address = realm.create(AddressModel, payload.address);
              }
              if (payload.remarks) {
                  response.remarks = payload.remarks;
              }
          }
          realm.commitTransaction();
      
          if (!options.realm) {
              response = response?.toJSON();
          }
      } catch (error) {
          console.log(error)
          console.log("Hey")
          if (realm?.isInTransaction === true) {
              realm?.cancelTransaction();
          }
      } finally {
          if (!options.realm) {
              realm?.close();
          }
      }
      

      Stacktrace & log output

      No response

      Can you reproduce the bug?

      Yes, always

      Reproduction Steps

      No response

      Version

      10.19.5

      What SDK flavour are you using?

      Local Database only

      Are you using encryption?

      No, not using encryption

      Platform OS and version(s)

      Node 14.x.x

      Build environment

      No response

      Cocoapods version

      No response

            Assignee:
            kenneth.geisshirt@mongodb.com Kenneth Geisshirt
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: