-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(Bulk): change BulkWriteError message to first item from writeErrors #2013
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! I left a couple of comments about the test to see if we can clean it up.
test/functional/bulk_tests.js
Outdated
@@ -937,6 +937,69 @@ describe('Bulk', function() { | |||
} | |||
}); | |||
|
|||
it( | |||
'should provide descriptive error message for Unordered Batch with duplicate key errors on updates', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can change this from Unordered Batch
to unordered batch
(no caps).
test/functional/bulk_tests.js
Outdated
it( | ||
'should provide descriptive error message for Unordered Batch with duplicate key errors on updates', | ||
{ | ||
metadata: { requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] } }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're allowing every topology here, we can change this test from
it('title', {
metadata: { requires: { topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'] } },
test: function(done) {
});
to
it('title', function(done) {
});
and it will run on all topology types.
test/functional/bulk_tests.js
Outdated
|
||
test: function(done) { | ||
const configuration = this.configuration; | ||
var client = configuration.newClient(configuration.writeConcernMax(), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you switch all of these var
s to const
? const
is more modern and we are trying to slowly modernize our tests by making any new tests modern.
test/functional/bulk_tests.js
Outdated
writeConcern.sparse = false; | ||
|
||
// Add unique index on b field causing all updates to fail | ||
col.ensureIndex({ b: 1 }, writeConcern, function(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since ensureIndex
is deprecated in favor of createIndexes
, can we use col.createIndexes
instead? Here are the docs for how to use createIndexes
.
test/functional/bulk_tests.js
Outdated
expect(result.nInserted).to.equal(2); | ||
expect(result.hasWriteErrors()).to.equal(true); | ||
expect( | ||
result.getWriteErrorCount() === 4 || result.getWriteErrorCount() === 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can change this test to ensure our error count is always 3. Maybe we can get rid of some of the batch.insert
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Just a couple of small changes.
test/functional/bulk_tests.js
Outdated
client.close(); | ||
done(); | ||
}); | ||
client.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this to client.close(done);
since we're here. This helps us modernize our tests.
test/functional/bulk_tests.js
Outdated
// Add unique index on b field causing all updates to fail | ||
col.ensureIndex({ b: 1 }, writeConcern, function(err) { | ||
expect(err).to.not.exist; | ||
client.connect(function(err, client) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all callbacks in this test, let's use (err, client) => {
notation instead of function(err, client) {
.
lib/bulk/common.js
Outdated
@@ -1119,7 +1119,7 @@ class BulkOperationBase { | |||
callback, | |||
new BulkWriteError( | |||
toError({ | |||
message: 'write operation failed', | |||
message: this.s.bulkResult.writeErrors[0].errmsg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this.s.bulkResult.writeErrors[0]
or its errmsg
doesn't exist? Let's check that the errmsg
exists and use the default write operation failed
message if not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me!
Fixes NODE-1965
Description
An unspecific
BulkWriteError: write operation failed
message was changed to the first item fromwriteErrors
.What changed?
A user requested to make the error more specific and suggested to use the first item from
writeErrors
. A change was made to theMongoError
message field to reflect this error message.