huan / flash-store

FlashStore is a high-performance Key-Value Persistent Local Database using ES6 Map's API (Async & Sync), Powered by LevelDB/RocksDB/SQLite and TypeScript.
https://paka.dev/npm/flash-store
Apache License 2.0
20 stars 4 forks source link

Throw error when running, currently not sure what's the reproduce steps #72

Closed windmemory closed 4 years ago

windmemory commented 4 years ago
(node:9) UnhandledPromiseRejectionWarning: ReadError: Unexpected end of JSON input
    at /xiaoju-bot/node_modules/levelup/lib/levelup.js:194:15
    at /xiaoju-bot/node_modules/encoding-down/index.js:79:14
    at /xiaoju-bot/node_modules/medeadown/medeadown.js:129:7
    at /xiaoju-bot/node_modules/medea/medea.js:551:15
    at FSReqWrap.wrapper [as oncomplete] (fs.js:463:17)
(node:9) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 518)

Code in the levelup.js

LevelUP.prototype.get = function (key, options, callback) {
  if (key === null || key === undefined) {
    throw new ReadError('get() requires a key argument')
  }

  var promise

  callback = getCallback(options, callback)

  if (!callback) {
    callback = promisify()
    promise = callback.promise
  }

  if (maybeError(this, callback)) { return promise }

  options = getOptions(options)

  this.db.get(key, options, function (err, value) {
    if (err) {
      if ((/notfound/i).test(err) || err.notFound) {
        err = new NotFoundError('Key not found in database [' + key + ']', err)
      } else {
        err = new ReadError(err)
      }
      return callback(err)
    }
    callback(null, value)
  })

  return promise
}

When called the db.get(), it throws the error.

Open this issue for recording the error stack, currently I don't know how to reproduce this issue since the error stack is too short.

huan commented 4 years ago

This bug should now exit with our latest stable version v0.20.