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.

levelup constructor without callback causes unhandled rejection

See original GitHub issue

Using v4.0.1 of levelup and leveldown. The following command causes an unhandled rejection:

levelup(leveldown('/path/to/nonexistent/file'))

UnhandledPromiseRejectionWarning: OpenError: IO error: /path/to/nonexistent/file: No such file or directory
....
    at (node:69500) 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: 1)

This happens because the final line in the LevelUP constructor, this.open(callback), is a floating promise.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
vweeverscommented, Jun 9, 2019

Aye. The unhandled rejection is somewhat consistent with the previous behavior of emitting an error event, but the difference is you can’t catch it now. Perhaps we should change this line:

https://github.com/Level/levelup/blob/c56f863e41f1b00216837963be34d4ba74458b19/lib/levelup.js#L57

To:

this.open(callback || function (err {
  if (err) self.emit('error', err)
})
0reactions
vweeverscommented, Oct 3, 2019

Fixed in 4.3.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Errors in JavaScript: The Definitive Guide
Now the Error instance alone does not cause anything. ... Unhandled promise rejection (rejection id: 1): Error: something went wrong
Read more >
What is an unhandled promise rejection? - Stack Overflow
In my case was Promise with no reject neither resolve, because my Promise function threw an exception. This mistake cause UnhandledPromiseRejectionWarning ...
Read more >
The way JavaScript ES8 made me to STOP writing call back ...
Even worse, there's no error checking, so any of the callbacks could fail silently as an unhandled promise rejection. Promise Chain. Let's make...
Read more >
Developing Async Sense in JavaScript — Part III: Promises
We instantiate the Promise constructor and give it a callback ... A Promise makes no assumptions on how or where we'll process its...
Read more >
JavaScript Promise Guides - DEV Community ‍ ‍
How to rewrite a callback function in Promise form and async/await form in ... I get the error: UnhandledPromiseRejectionWarning: TypeError: Cannot read ...
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