Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

fix(error): attach command response to MongoWriteConcernError #322

Merged
merged 3 commits into from
Jun 21, 2018

Conversation

kvwalker
Copy link
Contributor

Fixes NODE-1521

@kvwalker kvwalker requested review from mbroadst and daprahamian June 20, 2018 18:22
lib/error.js Outdated
const MongoWriteConcernError = function(message) {
MongoError.call(this, message);
const MongoWriteConcernError = function(message, result) {
MongoError.call(this, message, result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to pass result to MongoError? It doesn't appear to do anything with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, thanks for catching that!

@@ -581,6 +581,13 @@ function messageHandler(self) {
}

if (responseDoc.writeConcernError) {
if (responseDoc.ok === 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about doing a ternary to create the error, and then using a single callback?

if (responseDoc.writeConcernError) {
  const err = responseDoc.ok === 1 ?
    new MongoWriteConcernError(responseDoc.writeConcernError, responseDoc) :
    new MongoWriteConcernError(responseDoc.writeConcernError);
  return handleOperationCallback(self, workItem.cb, err);
}

lib/error.js Outdated
@@ -131,12 +131,17 @@ function isRetryableError(error) {
* @class
* @param {Error|string|object} message The error message
* @property {string} message The error message
* @property {object} result The result document (provided if ok: 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap the name of the argument with brackets to indicate it is optional, and add it to the @param documentation.

@kvwalker kvwalker merged commit 24c5d06 into mongodb-js:master Jun 21, 2018
@kvwalker kvwalker deleted the NODE-1521 branch June 21, 2018 16:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants