-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Field Level Encryption
-
Labels:
What problem are you facing?
collection.bulkWrite() calls do not properly forward errors that come from the libmongocrypt bindings.
What driver and relevant dependency versions are you using?
mongodb 4.6.0, mongodb-client-encryption 2.1.0
Steps to reproduce?
import { UUID } from 'bson'; import { MongoClient } from 'mongodb'; const client = await MongoClient.connect('mongodb://localhost', { autoEncryption: { keyVaultNamespace: 'test.keyvault', kmsProviders: { local: { key: 'A'.repeat(128) } }, encryptedFieldsMap: { 'test.coll': { fields: [{ path: 'ssn', // This keyId does *not* exist keyId: new UUID('23f786b4-1d39-4c36-ae88-70a663321ec9').toBinary(), bsonType: 'string' }], } } } }); await client.db('test').collection('coll').bulkWrite([{insertOne: { ssn: 'foo' }}]); // Works: await client.db('test').collection('coll').insertOne({ ssn: 'foo' }); await client.close();
leads to
TypeError: Cannot set property name of which has only a getter at new MongoServerError (/tmp/node_modules/mongodb/lib/error.js:137:28) at new MongoBulkWriteError (/tmp/node_modules/mongodb/lib/bulk/common.js:470:9) at resultHandler (/tmp/node_modules/mongodb/lib/bulk/common.js:390:29) at /tmp/node_modules/mongodb/lib/utils.js:413:17 at /tmp/node_modules/mongodb/lib/operations/execute_operation.js:58:17 at /tmp/node_modules/mongodb/lib/operations/execute_operation.js:161:32 at /tmp/node_modules/mongodb/lib/cmap/connection_pool.js:270:25 at /tmp/node_modules/mongodb/lib/sdam/server.js:212:17 at handleOperationResult (/tmp/node_modules/mongodb/lib/sdam/server.js:342:20) at /tmp/node_modules/mongodb/lib/cmap/connection.js:416:17
The original value of message in the MongoServerError constructor is this error from libmongocrypt:
MongoCryptError: not all keys requested were satisfied at StateMachine.execute (/tmp/node_modules/mongodb-client-encryption/lib/stateMachine.js:232:20) at /tmp/node_modules/mongodb-client-encryption/lib/stateMachine.js:174:18 at /tmp/node_modules/mongodb-client-encryption/lib/stateMachine.js:470:11 at /tmp/node_modules/mongodb/lib/utils.js:423:9 at /tmp/node_modules/mongodb/lib/cursor/abstract_cursor.js:249:32 at next (/tmp/node_modules/mongodb/lib/cursor/abstract_cursor.js:490:16) at /tmp/node_modules/mongodb/lib/cursor/abstract_cursor.js:504:20 at /tmp/node_modules/mongodb/lib/cursor/abstract_cursor.js:464:66 at /tmp/node_modules/mongodb/lib/utils.js:423:9 at completeEndSession (/tmp/node_modules/mongodb/lib/sessions.js:152:17)
Since it has a name property, but MongoServerError only has a getter for name, copying this property fails.