Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2078

Improve error message for missing `mongodb-client-encryption`

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.3.0
    • Affects Version/s: None
    • Component/s: Native
    • None

      Currently, we have the following code:

          let AutoEncrypter;
          try {
            AutoEncrypter = require('mongodb-client-encryption').AutoEncrypter;
          } catch (err) {
            callback(
              new MongoError(
                'Auto-encryption requested, but the module is not installed. Please add `mongodb-client-encryption` as a dependency of your project'
              )
            );
      
            return;
          }
      

      This is assuming that a failure to import mongodb-client-encryption stems from the module not existing. However, there are other errors that can cause the import to fail. For example, if libmongocrypt is improperly installed, attempting to {{require('mongodb-client-encryption');` will result in an error even if the module exists.

      We should instead do something along the lines of.

        let AutoEncrypter;
          try {
            require.resolve('mongodb-client-encryption');
          } catch (err) {
            callback(
              new MongoError(
                'Auto-encryption requested, but the module is not installed. Please add `mongodb-client-encryption` as a dependency of your project'
              )
            );
      
            return;
          }
          try {
            AutoEncrypter = require('mongodb-client-encryption').AutoEncrypter;
          } catch (err) {
            callback(err);// maybe wrap this in a MongoClientEncryptionError?
            return;
          }
        }
      

            Assignee:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Reporter:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: