Skip to content

refactor!: Clarify empty BulkOperation error message #2697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bulk/common.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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