Use only null for err if no error

pull/2/head
Louis Chatriot 12 years ago
parent 8ac65a7cbc
commit ccc766ca2a
  1. 12
      lib/datastore.js
  2. 2
      package.json
  3. 2
      test/db.test.js

@ -97,7 +97,7 @@ Datastore.prototype.ensureIndex = function (options, cb) {
options = options || {};
if (!options.fieldName) { return callback({ missingFieldName: true }); }
if (this.indexes[options.fieldName]) { return callback(); }
if (this.indexes[options.fieldName]) { return callback(null); }
this.indexes[options.fieldName] = new Index(options);
@ -108,7 +108,7 @@ Datastore.prototype.ensureIndex = function (options, cb) {
return callback(e);
}
return callback();
return callback(null);
};
@ -253,7 +253,7 @@ Datastore.prototype._loadDatabase = function (cb) {
self.datafileSize = 0;
// In-memory only datastore
if (self.inMemoryOnly) { return callback(); }
if (self.inMemoryOnly) { return callback(null); }
customUtils.ensureDirectoryExists(path.dirname(self.filename), function (err) {
fs.exists(self.filename, function (exists) {
@ -336,7 +336,7 @@ Datastore.prototype.persistCachedDatabase = function (cb) {
toPersist += model.serialize(doc) + '\n';
});
if (toPersist.length === 0) { return callback(); }
if (toPersist.length === 0) { return callback(null); }
fs.writeFile(this.filename, toPersist, function (err) { return callback(err); });
};
@ -355,7 +355,7 @@ Datastore.prototype._persistNewState = function (newDocs, cb) {
;
// In-memory only datastore
if (self.inMemoryOnly) { return callback(); }
if (self.inMemoryOnly) { return callback(null); }
self.datafileSize += newDocs.length;
@ -363,7 +363,7 @@ Datastore.prototype._persistNewState = function (newDocs, cb) {
toPersist += model.serialize(doc) + '\n';
});
if (toPersist.length === 0) { return callback(); }
if (toPersist.length === 0) { return callback(null); }
fs.appendFile(self.filename, toPersist, 'utf8', function (err) {
return callback(err);

@ -1,6 +1,6 @@
{
"name": "nedb",
"version": "0.7.11",
"version": "0.7.12",
"author": {
"name": "tldr.io",
"email": "hello@tldr.io"

@ -1528,7 +1528,7 @@ describe('Database', function () {
d.insert({ a: 2, b: 45 }, function () {
d.insert({ a: 1, b: 3 }, function () {
d.ensureIndex({ fieldName: 'b' }, function (err) {
assert.isUndefined(err);
assert.isNull(err);
d.ensureIndex({ fieldName: 'a', unique: true }, function (err) {
err.errorType.should.equal('uniqueViolated');

Loading…
Cancel
Save