Skip to content

Commit aae949c

Browse files
committed
Ensures that errors from bulk unordered and ordered are instanceof Error.
1 parent 70ceff3 commit aae949c

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

lib/bulk/ordered.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ var executeCommands = function(self, callback) {
402402
// If we are ordered and have errors and they are
403403
// not all replication errors terminate the operation
404404
if(self.s.bulkResult.writeErrors.length > 0) {
405-
return callback(self.s.bulkResult.writeErrors[0], new BulkWriteResult(self.s.bulkResult));
405+
return callback(toError(self.s.bulkResult.writeErrors[0]), new BulkWriteResult(self.s.bulkResult));
406406
}
407407

408408
// Execute the next command in line

lib/bulk/unordered.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ var executeBatches = function(self, callback) {
431431

432432
// Execute
433433
if(numberOfCommandsToExecute == 0) {
434-
var error = self.s.bulkResult.writeErrors.length > 0 ? self.s.bulkResult.writeErrors[0] : null;
434+
var error = self.s.bulkResult.writeErrors.length > 0 ? toError(self.s.bulkResult.writeErrors[0]) : null;
435435
callback(error, new BulkWriteResult(self.s.bulkResult));
436436
}
437437
});

test/functional/bulk_tests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ exports['Should correctly handle ordered multiple batch api write command error'
8282
// Execute the operations
8383
batch.execute(function(err, result) {
8484
// Basic properties check
85+
test.equal(err instanceof Error, true);
8586
test.equal(1, result.nInserted);
8687
test.equal(true, result.hasWriteErrors());
8788
test.ok(1, result.getWriteErrorCount());
@@ -484,6 +485,7 @@ exports['Should correctly handle single unordered batch API'] = {
484485
// Execute the operations
485486
batch.execute(function(err, result) {
486487
// Basic properties check
488+
test.equal(err instanceof Error, true);
487489
test.equal(2, result.nInserted);
488490
test.equal(0, result.nUpserted);
489491
test.equal(0, result.nMatched);

0 commit comments

Comments
 (0)