Skip to content

Commit 34f488d

Browse files
authored
refactor!: Clarify empty BulkOperation error message (#2697)
Update tests to assert TypeError is used for this API misuse NODE-2961
1 parent 85d8d09 commit 34f488d

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/bulk/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ export abstract class BulkOperationBase {
12021202
}
12031203
// If we have no operations in the bulk raise an error
12041204
if (this.s.batches.length === 0) {
1205-
const emptyBatchError = new TypeError('Invalid Operation, no operations specified');
1205+
const emptyBatchError = new TypeError('Invalid BulkOperation, Batch cannot be empty');
12061206
return handleEarlyError(emptyBatchError, callback);
12071207
}
12081208

test/functional/bulk.test.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ describe('Bulk', function () {
596596
var col = db.collection('batch_write_ordered_ops_8');
597597

598598
col.initializeOrderedBulkOp().execute(function (err) {
599-
test.equal(err instanceof Error, true);
600-
test.equal(err.message, 'Invalid Operation, no operations specified');
599+
expect(err).to.be.instanceOf(TypeError);
600+
expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty');
601601

602602
client.close(done);
603603
});
@@ -1105,8 +1105,8 @@ describe('Bulk', function () {
11051105
col
11061106
.initializeUnorderedBulkOp()
11071107
.execute(self.configuration.writeConcernMax(), function (err) {
1108-
test.equal(err instanceof Error, true);
1109-
test.equal(err.message, 'Invalid Operation, no operations specified');
1108+
expect(err).to.be.instanceOf(TypeError);
1109+
expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty');
11101110

11111111
client.close(done);
11121112
});
@@ -1516,8 +1516,9 @@ describe('Bulk', function () {
15161516
client.connect(function (err, client) {
15171517
var db = client.db(self.configuration.db);
15181518
db.collection('doesnt_matter').insertMany([], function (err) {
1519-
test.equal(err instanceof Error, true);
1520-
test.equal(err.message, 'Invalid Operation, no operations specified');
1519+
expect(err).to.be.instanceOf(TypeError);
1520+
expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty');
1521+
15211522
client.close(done);
15221523
});
15231524
});
@@ -1536,8 +1537,9 @@ describe('Bulk', function () {
15361537
client.connect(function (err, client) {
15371538
var db = client.db(self.configuration.db);
15381539
db.collection('doesnt_matter').insertMany([], { ordered: false }, function (err) {
1539-
test.equal(err instanceof Error, true);
1540-
test.equal(err.message, 'Invalid Operation, no operations specified');
1540+
expect(err).to.be.instanceOf(TypeError);
1541+
expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty');
1542+
15411543
client.close(done);
15421544
});
15431545
});
@@ -1559,8 +1561,8 @@ describe('Bulk', function () {
15591561
test.equal(false, true); // this should not happen!
15601562
})
15611563
.catch(function (err) {
1562-
test.equal(err instanceof Error, true);
1563-
test.equal(err.message, 'Invalid Operation, no operations specified');
1564+
expect(err).to.be.instanceOf(TypeError);
1565+
expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty');
15641566
})
15651567
.then(function () {
15661568
return client.close();

0 commit comments

Comments
 (0)