Skip to content

Commit 7d250d1

Browse files
committed
NODE-506 What is the proper error handling mechanism for bulk/batch operations?
2 parents 39a61e3 + aae949c commit 7d250d1

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
2.0.40 07-14-2015
22
-----------------
33
- Updated mongodb-core to 1.2.7 for APM support.
4+
- NODE-506 Ensures that errors from bulk unordered and ordered are instanceof Error (Issue #1282, https://github.com/owenallenaz).
45

56
2.0.39 07-14-2015
67
-----------------

lib/bulk/ordered.js

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

415415
// Execute the next command in line

lib/bulk/unordered.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ var executeBatches = function(self, callback) {
453453
// Driver level error
454454
if(error) return callback(error);
455455
// Treat write errors
456-
var error = self.s.bulkResult.writeErrors.length > 0 ? self.s.bulkResult.writeErrors[0] : null;
456+
var error = self.s.bulkResult.writeErrors.length > 0 ? toError(self.s.bulkResult.writeErrors[0]) : null;
457457
callback(error, new BulkWriteResult(self.s.bulkResult));
458458
}
459459
});

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());
@@ -454,6 +455,7 @@ exports['Should correctly handle single unordered batch API'] = {
454455
// Execute the operations
455456
batch.execute(function(err, result) {
456457
// Basic properties check
458+
test.equal(err instanceof Error, true);
457459
test.equal(2, result.nInserted);
458460
test.equal(0, result.nUpserted);
459461
test.equal(0, result.nMatched);

0 commit comments

Comments
 (0)