Coder Social home page Coder Social logo

Comments (2)

CMCDragonkai avatar CMCDragonkai commented on May 27, 2024

I found a way to do this:

      return await new Promise<DBLevel>((resolve, reject) => {
        const dbLevelNew = subleveldown(dbLevel, domain, {
          keyEncoding: 'binary',
          valueEncoding: 'binary',
          open: (cb) => {
            // This `cb` is defaulted (hardcoded) to a function that emits an error event
            // When using `level`, we are able to provide a callback that overrides this `cb`
            // However `subleveldown` does not provide a callback parameter
            // It provides this `open` option, which requires us to call `cb` to finish
            // If we provide an exception as a parameter, it will be received by the `error` event handler
            cb(undefined);
            resolve(dbLevelNew);
          },
        });
        // @ts-ignore error event for subleveldown
        dbLevelNew.on('error', (e) => {
          // Errors during construction of the sublevel will be emitted as events
          reject(e);
        });
      });

It would preferable that subleveldown matches the API of level, and level provides the ability to just pass the callback.

Atm even the types think that error is not a legitimate event. But it is indeed emitted.

Now I can actually handle the error properly:

(node:4099911) UnhandledPromiseRejectionWarning: OpenError: Inner database is not open
    at /home/cmcdragonkai/Projects/js-db/node_modules/subleveldown/node_modules/levelup/lib/levelup.js:119:23
    at /home/cmcdragonkai/Projects/js-db/node_modules/deferred-leveldown/node_modules/abstract-leveldown/abstract-leveldown.js:38:14
    at /home/cmcdragonkai/Projects/js-db/node_modules/deferred-leveldown/deferred-leveldown.js:31:21
    at /home/cmcdragonkai/Projects/js-db/node_modules/encoding-down/node_modules/abstract-leveldown/abstract-leveldown.js:38:14
    at /home/cmcdragonkai/Projects/js-db/node_modules/subleveldown/node_modules/abstract-leveldown/abstract-leveldown.js:38:14
    at onopen (/home/cmcdragonkai/Projects/js-db/node_modules/subleveldown/leveldown.js:142:50)
    at processTicksAndRejections (internal/process/task_queues.js:77:11)

from subleveldown.

vweevers avatar vweevers commented on May 27, 2024

It would preferable that subleveldown matches the API of level

On that point: https://github.com/Level/abstract-level

from subleveldown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.