Skip to content

Commit

Permalink
docs: make a note on each optional require that using try is necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Jul 16, 2021
1 parent 5106f2d commit 02bae84
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/core/auth/mongodb_aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const url = require('url');

let aws4;
try {
// Ensure you always wrap an optional require in the try block NODE-3199
aws4 = require('aws4');
} catch (e) {
// don't do anything;
Expand Down
1 change: 1 addition & 0 deletions lib/core/auth/scram.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Binary = BSON.Binary;

let saslprep;
try {
// Ensure you always wrap an optional require in the try block NODE-3199
saslprep = require('saslprep');
} catch (e) {
// don't do anything;
Expand Down
1 change: 1 addition & 0 deletions lib/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const require_optional = require('optional-require')(require);
const EJSON = require('./utils').retrieveEJSON();

try {
// Ensure you always wrap an optional require in the try block NODE-3199
// Attempt to grab the native BSON parser
const BSONNative = require_optional('bson-ext');
// If we got the native parser, use it instead of the
Expand Down
1 change: 1 addition & 0 deletions lib/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function retrieveKerberos() {
let kerberos;

try {
// Ensure you always wrap an optional require in the try block NODE-3199
kerberos = requireOptional('kerberos');
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
Expand Down
1 change: 1 addition & 0 deletions lib/encrypter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const MongoError = require('./core/error').MongoError;

let mongodbClientEncryption = undefined;
try {
// Ensure you always wrap an optional require in the try block NODE-3199
mongodbClientEncryption = require('mongodb-client-encryption');
} catch (err) {
throw new MongoError(
Expand Down

0 comments on commit 02bae84

Please sign in to comment.