question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug in promisification of get

See original GitHub issue

It looks to me like get doesn’t perform as it should for promises …

const level = require('level');
async function test() {
        this.config = {dir: "testleveldb."};
        let db = level('testleveldb.Testtable');
        await db.put("testkey", "testval");
        let res = await db.get("testkey");
        console.assert(res === "testval");
}
test();

Should work, i.e. the db.get will return a promise to be awaited. But it errors …
ReadError: get() requires key and callback arguments

Replacing the 'await db.get` line with a callback e.g.

    db.get("testkey", function(err, res) {
        if (err) { console.log("Err",err); }
        console.log("res=",res)
        console.assert(res === "testval");
    });

Works, so it looks like get is erroneously checking its arguments for a callback when according to the Readme its supposed to allow this to be undefined and return a promise.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mitra42commented, Apr 5, 2018

Thanks for prompt response … That might be the problem - looks like its using an earlier version of level in a different dependency, let me update and I’ll close this issue if it fixes the issue.

0reactions
vweeverscommented, Sep 13, 2020

Feel free to open a new issue with details and a repro, so we can take a closer look at what’s happening there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Different behaviour when using util.promisify #4305 - GitHub
Do you want to request a feature or report a bug? bug What is the current behavior? test('should return 1', async () =>...
Read more >
Javascript: No More callbacks, Use Promisify to Convert ...
We need to convert callback to promise because the promise is more readable and easier to handle.
Read more >
Jest doesn't work with util.promisify(setTimeout) - Stack Overflow
This is an interesting question. It gets all the way down to the implementation of core built-in functions.
Read more >
Promisification - The Modern JavaScript Tutorial
“Promisification” is a long word for a simple transformation. It's the conversion of a function that accepts a callback into a function that ......
Read more >
886848 - Promisify the debugger frontend - Bugzilla@Mozilla
I'm renaming this bug to "Promisify the debugger frontend" since that's what I've been ... and uses promises to make sure things don't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found