handle notfound errors at a lower level.
This commit is contained in:
parent
c6af30e69d
commit
bd56b46806
@ -456,7 +456,7 @@ ChainDB.prototype.getEntry = function getEntry(hash, callback) {
|
|||||||
return utils.nextTick(callback);
|
return utils.nextTick(callback);
|
||||||
|
|
||||||
return this.getHash(hash, function(err, hash) {
|
return this.getHash(hash, function(err, hash) {
|
||||||
if (err && err.type !== 'NotFoundError')
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (!hash)
|
if (!hash)
|
||||||
|
|||||||
@ -124,10 +124,8 @@ LowlevelUp.prototype.get = function get(key, options, callback) {
|
|||||||
|
|
||||||
return this.binding.get(key, options, function(err, result) {
|
return this.binding.get(key, options, function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err.notFound || /not\s*found/i.test(err.message)) {
|
if (isNotFound(err))
|
||||||
err.notFound = true;
|
return callback();
|
||||||
err.type = 'NotFoundError';
|
|
||||||
}
|
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
return callback(null, result);
|
return callback(null, result);
|
||||||
@ -222,7 +220,7 @@ LowlevelUp.prototype.approximateSize = function approximateSize(start, end, call
|
|||||||
|
|
||||||
LowlevelUp.prototype.has = function has(key, callback) {
|
LowlevelUp.prototype.has = function has(key, callback) {
|
||||||
return this.get(key, function(err, value) {
|
return this.get(key, function(err, value) {
|
||||||
if (err && err.type !== 'NotFoundError')
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
return callback(null, value != null);
|
return callback(null, value != null);
|
||||||
@ -239,7 +237,7 @@ LowlevelUp.prototype.has = function has(key, callback) {
|
|||||||
|
|
||||||
LowlevelUp.prototype.fetch = function fetch(key, parse, callback) {
|
LowlevelUp.prototype.fetch = function fetch(key, parse, callback) {
|
||||||
return this.get(key, function(err, value) {
|
return this.get(key, function(err, value) {
|
||||||
if (err && err.type !== 'NotFoundError')
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (!value)
|
if (!value)
|
||||||
@ -265,6 +263,8 @@ LowlevelUp.prototype.iterate = function iterate(options, callback) {
|
|||||||
var items = [];
|
var items = [];
|
||||||
var iter, opt;
|
var iter, opt;
|
||||||
|
|
||||||
|
assert(this.loaded, 'Cannot use database before it is loaded.');
|
||||||
|
|
||||||
opt = {
|
opt = {
|
||||||
gte: options.gte,
|
gte: options.gte,
|
||||||
lte: options.lte,
|
lte: options.lte,
|
||||||
@ -354,7 +354,7 @@ LowlevelUp.prototype.lookup = function lookup(options, callback) {
|
|||||||
|
|
||||||
utils.forEachSerial(keys, function(key, next) {
|
utils.forEachSerial(keys, function(key, next) {
|
||||||
self.get(key, function(err, value) {
|
self.get(key, function(err, value) {
|
||||||
if (err && err.type !== 'NotFoundError')
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (!value)
|
if (!value)
|
||||||
@ -381,6 +381,19 @@ LowlevelUp.prototype.lookup = function lookup(options, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helpers
|
||||||
|
*/
|
||||||
|
|
||||||
|
function isNotFound(err) {
|
||||||
|
if (!err)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return err.notFound
|
||||||
|
|| err.type === 'NotFoundError'
|
||||||
|
|| /not\s*found/i.test(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expose
|
* Expose
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -215,7 +215,7 @@ TXDB.prototype._addOrphan = function _addOrphan(key, hash, index, callback) {
|
|||||||
var p;
|
var p;
|
||||||
|
|
||||||
this.db.get('o/' + key, function(err, buf) {
|
this.db.get('o/' + key, function(err, buf) {
|
||||||
if (err && err.type !== 'NotFoundError')
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
p = new BufferWriter();
|
p = new BufferWriter();
|
||||||
|
|||||||
@ -431,8 +431,8 @@ WalletDB.prototype.get = function get(id, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.db.get('w/' + id, function(err, data) {
|
this.db.get('w/' + id, function(err, data) {
|
||||||
if (err && err.type !== 'NotFoundError')
|
if (err)
|
||||||
return callback();
|
return callback(err);
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
return callback();
|
return callback();
|
||||||
@ -577,7 +577,7 @@ WalletDB.prototype.getAccount = function getAccount(id, name, callback) {
|
|||||||
return callback();
|
return callback();
|
||||||
|
|
||||||
self.db.get('a/' + id + '/' + index, function(err, data) {
|
self.db.get('a/' + id + '/' + index, function(err, data) {
|
||||||
if (err && err.type !== 'NotFoundError')
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
@ -640,8 +640,8 @@ WalletDB.prototype.getAccountIndex = function getAccountIndex(id, name, callback
|
|||||||
return callback(null, name);
|
return callback(null, name);
|
||||||
|
|
||||||
this.db.get('i/' + id + '/' + name, function(err, index) {
|
this.db.get('i/' + id + '/' + name, function(err, index) {
|
||||||
if (err && err.type !== 'NotFoundError')
|
if (err)
|
||||||
return callback();
|
return callback(err);
|
||||||
|
|
||||||
if (!index)
|
if (!index)
|
||||||
return callback(null, -1);
|
return callback(null, -1);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user