diff --git a/lib/batch.js b/lib/batch.js index 12972241..b069df80 100644 --- a/lib/batch.js +++ b/lib/batch.js @@ -6,7 +6,6 @@ var util = require('./util') var WriteError = require('level-errors').WriteError -var dispatchError = util.dispatchError var promisify = util.promisify function Batch (levelup) { @@ -64,7 +63,7 @@ Batch.prototype.write = function (callback) { try { this.batch.write(function (err) { - if (err) { return dispatchError(levelup, new WriteError(err), callback) } + if (err) { return callback(new WriteError(err)) } levelup.emit('batch', ops) callback() }) diff --git a/lib/levelup.js b/lib/levelup.js index a4bade24..db9feb86 100644 --- a/lib/levelup.js +++ b/lib/levelup.js @@ -20,7 +20,6 @@ var NotFoundError = errors.NotFoundError var OpenError = errors.OpenError var InitializationError = errors.InitializationError -var dispatchError = util.dispatchError var promisify = util.promisify // Possible AbstractLevelDOWN#status values: @@ -86,7 +85,7 @@ LevelUP.prototype.open = function (callback) { this.db.open(this.options, function (err) { if (err) { - return dispatchError(self, new OpenError(err), callback) + return callback(new OpenError(err)) } self.db = self._db callback(null, self) @@ -140,7 +139,6 @@ LevelUP.prototype.get = function (key, options, callback) { throw new ReadError('get() requires a key argument') } - var self = this var promise callback = getCallback(options, callback) @@ -158,7 +156,7 @@ LevelUP.prototype.get = function (key, options, callback) { } else { err = new ReadError(err) } - return dispatchError(self, err, callback) + return callback(err) } callback(null, value) }) @@ -184,7 +182,7 @@ LevelUP.prototype.put = function (key, value, options, callback) { this.db.put(key, value, options, function (err) { if (err) { - return dispatchError(self, new WriteError(err), callback) + return callback(new WriteError(err)) } self.emit('put', key, value) callback() @@ -211,7 +209,7 @@ LevelUP.prototype.del = function (key, options, callback) { this.db.del(key, options, function (err) { if (err) { - return dispatchError(self, new WriteError(err), callback) + return callback(new WriteError(err)) } self.emit('del', key) callback() @@ -247,7 +245,7 @@ LevelUP.prototype.batch = function (arr, options, callback) { this.db.batch(arr, options, function (err) { if (err) { - return dispatchError(self, new WriteError(err), callback) + return callback(new WriteError(err)) } self.emit('batch', arr) callback() @@ -287,7 +285,7 @@ function getOptions (options) { function maybeError (db, callback) { if (!db._isOpening() && !db.isOpen()) { - dispatchError(db, new ReadError('Database is not open'), callback) + callback(new ReadError('Database is not open')) return true } } diff --git a/lib/util.js b/lib/util.js index 17388878..77322b3a 100644 --- a/lib/util.js +++ b/lib/util.js @@ -4,10 +4,6 @@ * */ -function dispatchError (db, error, callback) { - typeof callback === 'function' ? callback(error) : db.emit('error', error) -} - function promisify () { var callback var promise = new Promise(function (resolve, reject) { @@ -20,6 +16,5 @@ function promisify () { } module.exports = { - dispatchError: dispatchError, promisify: promisify }