How to use the levelup.errors function in levelup

To help you get started, we’ve selected a few levelup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitpay / bitcore-node / lib / services / db.js View on Github external
self.store.get(DB.PREFIXES.VERSION, options, function(err, buffer) {
      var version;
      if (err instanceof levelup.errors.NotFoundError) {
        // The initial version (1) of the database didn't store the version number
        version = 1;
      } else if (err) {
        return callback(err);
      } else {
        version = buffer.readUInt32BE();
      }
      if (self.version !== version) {
        var helpUrl = 'https://github.com/bitpay/bitcore-node/blob/master/docs/services/db.md#how-to-reindex';
        return callback(new Error(
          'The version of the database "' + version + '" does not match the expected version "' +
            self.version + '". A recreation of "' + self.dataPath + '" (can take several hours) is ' +
            'required or to switch versions of software to match. Please see ' + helpUrl +
            ' for more information.'
        ));
      }
github fastify / fastify-leveldb / index.js View on Github external
// mostly from level-packager
const levelMore = (location, options) => {
  if (typeof options !== 'object' || options === null) options = {}
  const store = options.store || leveldown
  delete options.store
  ;['destroy', 'repair'].forEach(function (m) {
    if (typeof store[m] === 'function') {
      levelMore[m] = () => store[m].apply(store, arguments)
    }
  })

  return levelup(encode(store(location), options), options)
}

levelMore.errors = levelup.errors

function levelPlugin (fastify, opts, next) {
  if (!opts.name && (!opts.options || !opts.options.store)) {
    return next(new Error('Missing database name'))
  }
  opts.options = opts.options || {}

  fastify
    .decorate('level', levelMore(opts.name, opts.options))
    .addHook('onClose', close)

  next()
}

function close (fastify, done) {
  fastify.level.close(done)
github bitpay / bitcore-node / lib / services / db.js View on Github external
self.store.get(DB.PREFIXES.TIP, options, function(err) {
    if (err instanceof levelup.errors.NotFoundError) {
      // The database is brand new and doesn't have a tip stored
      // we can skip version checking
      return callback();
    } else if (err) {
      return callback(err);
    }
    self.store.get(DB.PREFIXES.VERSION, options, function(err, buffer) {
      var version;
      if (err instanceof levelup.errors.NotFoundError) {
        // The initial version (1) of the database didn't store the version number
        version = 1;
      } else if (err) {
        return callback(err);
      } else {
        version = buffer.readUInt32BE();
      }
github bitpay / bitcore-node / test / services / db.unit.js View on Github external
it('will NOT check the version if a tip is not found', function(done) {
      var db = new DB(config);
      db.store = {};
      db.store.get = sinon.stub().callsArgWith(2, new levelup.errors.NotFoundError());
      db._checkVersion(done);
    });
    it('will NOT give an error if the versions match', function(done) {
github bitpay / bitcore-node / test / services / db.unit.js View on Github external
it('genesis block if no metadata is found in the db', function(done) {
      var db = new DB(baseConfig);
      db.genesis = Block.fromBuffer(genesisBuffer);
      db.store = {
        get: sinon.stub().callsArgWith(2, new levelup.errors.NotFoundError())
      };
      db.connectBlock = sinon.stub().callsArg(1);
      db.sync = sinon.stub();
      db.loadTip(function() {
        should.exist(db.tip);
        db.tip.hash.should.equal('00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206');
        done();
      });
    });
github bitpay / bitcore-node / lib / services / db / index.js View on Github external
this._store.get(key, opts, function(err, data) {

      if(err && err instanceof levelup.errors.NotFoundError) {
        return cb();
      }

      if (err) {
        return cb(err);
      }

      cb(null, data);

    });
github bitpay / bitcore-node / lib / services / address / index.js View on Github external
this.node.services.db.store.get(key, dbOptions, function(err, buffer) {
    if (err instanceof levelup.errors.NotFoundError) {
      return callback(null, false);
    } else if (err) {
      return callback(err);
    }
    var value = encoding.decodeInputValueMap(buffer);
    callback(null, {
      inputTxId: value.inputTxId.toString('hex'),
      inputIndex: value.inputIndex
    });
  });
};
github Level / packager / level-packager.js View on Github external
return levelup(encode(leveldown(location, options), options), options, callback)
  }

  function isObject (o) {
    return typeof o === 'object' && o !== null
  }

  ['destroy', 'repair'].forEach(function (m) {
    if (typeof leveldown[m] === 'function') {
      Level[m] = function () {
        leveldown[m].apply(leveldown, arguments)
      }
    }
  })

  Level.errors = levelup.errors

  return Level
}
github bitpay / bitcore-node / lib / services / block.js View on Github external
BlockService.prototype._getLatestHash = function() {
  var self = this;
  return Promise.try(function() {
    return self.database.getAsync(Index.tip);
  }).catch(LevelUp.errors.NotFoundError, function() {
    return null;
  });
};
/**
github Picolab / pico-engine / packages / pico-engine-core / src / DB.js View on Github external
ldb.get(["channel", eci], function (err, channel){
                if(err){
                    if(err.notFound){
                        err = new levelup.errors.NotFoundError("ECI not found: " + eci);
                        err.notFound = true;
                    }
                    callback(err);
                    return;
                }
                var privateKey = channel.sovrin.secret.encryptionPrivateKey;
                privateKey = bs58.decode(privateKey);
                var sharedSecret = channel.sovrin.sharedSecret;
                if (!sharedSecret) {
                    sharedSecret = sovrinDID.getSharedSecret(otherPublicKey, privateKey);
                    ldb.put(["channel", eci, "sovrin", "secret", "sharedSecret"], bs58.encode(sharedSecret), function (err) {
                        if (err) {
                            callback(err);
                        }
                    });
                }

levelup

Fast & simple storage - a Node.js-style LevelDB wrapper

MIT
Latest version published 3 years ago

Package Health Score

64 / 100
Full package analysis