Skip to content

Commit

Permalink
refactor!: Clarify empty BulkOperation error message (#2697)
Browse files Browse the repository at this point in the history
Update tests to assert TypeError is used for this API misuse

NODE-2961
  • Loading branch information
nbbeeken committed Jan 14, 2021
1 parent 85d8d09 commit 34f488d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/bulk/common.ts
Expand Up @@ -1202,7 +1202,7 @@ export abstract class BulkOperationBase {
}
// If we have no operations in the bulk raise an error
if (this.s.batches.length === 0) {
const emptyBatchError = new TypeError('Invalid Operation, no operations specified');
const emptyBatchError = new TypeError('Invalid BulkOperation, Batch cannot be empty');
return handleEarlyError(emptyBatchError, callback);
}

Expand Down
22 changes: 12 additions & 10 deletions test/functional/bulk.test.js
Expand Up @@ -596,8 +596,8 @@ describe('Bulk', function () {
var col = db.collection('batch_write_ordered_ops_8');

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

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

client.close(done);
});
Expand Down Expand Up @@ -1516,8 +1516,9 @@ describe('Bulk', function () {
client.connect(function (err, client) {
var db = client.db(self.configuration.db);
db.collection('doesnt_matter').insertMany([], function (err) {
test.equal(err instanceof Error, true);
test.equal(err.message, 'Invalid Operation, no operations specified');
expect(err).to.be.instanceOf(TypeError);
expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty');

client.close(done);
});
});
Expand All @@ -1536,8 +1537,9 @@ describe('Bulk', function () {
client.connect(function (err, client) {
var db = client.db(self.configuration.db);
db.collection('doesnt_matter').insertMany([], { ordered: false }, function (err) {
test.equal(err instanceof Error, true);
test.equal(err.message, 'Invalid Operation, no operations specified');
expect(err).to.be.instanceOf(TypeError);
expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty');

client.close(done);
});
});
Expand All @@ -1559,8 +1561,8 @@ describe('Bulk', function () {
test.equal(false, true); // this should not happen!
})
.catch(function (err) {
test.equal(err instanceof Error, true);
test.equal(err.message, 'Invalid Operation, no operations specified');
expect(err).to.be.instanceOf(TypeError);
expect(err).to.have.property('message', 'Invalid BulkOperation, Batch cannot be empty');
})
.then(function () {
return client.close();
Expand Down

0 comments on commit 34f488d

Please sign in to comment.