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.

why assert on an async callback

See original GitHub issue

using assert which throws an error if the data doesn’t match the parameters feels a little odd for a library with an async callback – why not call the callback with an error?

it feels very odd to protect myself from a crashing program with doing:

try {
  pwd.verify(pass, hash, cb) 
} catch (err) {
  cb(err)
}

Rather than just

pwd.verify(pass, has, cb)

Would you be open to a PR changing the async methods to call the callback instead of throwing an AssertionError?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mafintoshcommented, Jun 27, 2017

🔥 this is also why promises are terrible at error handling 🔥

0reactions
toddselfcommented, Jul 11, 2017

@emilbayes thank you for this. this feels much better from an “end developer”

Read more comments on GitHub >

github_iconTop Results From Across the Web

assert.async() - QUnit API
assert.async() returns a callback function and pauses test processing until the callback function is called. The callback will throw an Error if it...
Read more >
assertion inside a callback that was called by an async ...
Inside a it callback with the done parameter : Any async function taking callback as parameter and calling this very callback makes the...
Read more >
Expect.assertions in async/await function - Stack Overflow
Expect.assertions(number) verifies that a certain number of assertions are called during a test. This is often useful when testing asynchronous ...
Read more >
Testing Asynchronous Code - Jest
If you don't use promises, you can use callbacks. For example, let's say that fetchData , instead of returning a promise, expects a...
Read more >
QUnit - Async Call - Tutorialspoint
assert.async() accepts call counts as a parameter. The callback returned from assert.async() will throw an Error, if it is invoked more than the...
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