Skip to content

Commit

Permalink
Merge pull request #530 from aheckmann/error
Browse files Browse the repository at this point in the history
Fix empty MongoError "message" property
  • Loading branch information
christkv committed Mar 7, 2012
2 parents 9776062 + 7122392 commit da79a6d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
@@ -1,6 +1,6 @@
NODE = node
NPM = npm
NODEUNIT = deps/nodeunit/bin/nodeunit
NODEUNIT = node_modules/nodeunit/bin/nodeunit
DOX = node_modules/dox/bin/dox
name = all

Expand Down
3 changes: 2 additions & 1 deletion lib/mongodb/db.js
Expand Up @@ -1566,7 +1566,8 @@ Db.prototype._executeRemoveCommand = Db.prototype._executeInsertCommand;
* @api private
*/
Db.prototype.wrap = function(error) {
var e = new Error(error.err != null ? error.err : error.errmsg);
var msg = error.err || error.errmsg || error;
var e = new Error(msg);
e.name = 'MongoError';

// Get all object keys
Expand Down
16 changes: 16 additions & 0 deletions test/error_test.js
Expand Up @@ -289,6 +289,22 @@ exports.shouldHandleAssertionError = function(test) {
});
});
}

exports['mixing included and excluded fields should return an error object with message'] = function (test) {
client.createCollection('test_error_object_should_include_message', function(err, c) {
test.equal(err, null);
c.insert({a:2, b: 5}, {safe:true}, function(err, r) {
test.equal(err, null);
c.findOne({a:2}, {fields: {a:1, b:0}}, function(err) {
test.ok(err);
test.equal('object', typeof err);
var rgx = /You cannot currently mix including and excluding fields/;
test.ok(rgx.test(err.message), 'missing error message property');
test.done();
});
});
});
}

/**
* Retrieve the server information for the current
Expand Down

0 comments on commit da79a6d

Please sign in to comment.