-
Type: New Feature
-
Resolution: Fixed
-
Priority: Minor - P4
-
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; } }