7

Assume I have somewhere in my javascript code async function doSomething() {} and somewhere else I call this function without trying to fulfill it.

Just doSomething(); Not await doSomething(). (neither doSomething().then()). How do I find all these occurrences?

I just spent 10 hours chasing after an unknown promise that got resolved at some random point due to a missing await before the function call. I wish there is a way to find them all.

David
  • 2,528
  • 1
  • 23
  • 29
  • 1
    You could consider something like TypeScript, but I don't know of any way for static code analysis to discover these problems. – user229044 Oct 26 '18 at 19:36
  • If you use a type-checker, that'll help you - that way, for example, you'll be sure of whether something is a `Promise` or some other value – CertainPerformance Oct 26 '18 at 19:37
  • 1
    I thought it's an interesting enough question, a mistake I could easily see happening, and I can't think of an easy-ish way to solve it off the top of my head without seriously changing things around. – CertainPerformance Oct 26 '18 at 19:39
  • Possible duplicate of https://stackoverflow.com/questions/30564053/how-can-i-synchronously-determine-a-javascript-promises-state – rlemon Oct 26 '18 at 19:42
  • 2
    I think there's a decent question in here, if it's reworded around how to debug or avoid this class of bugs, and refrains from asking about a specific "scan" tool. - For instance, you could induce failure, and [check for unhandled reections](https://stackoverflow.com/a/43994999/918910). One more comment: you say it's "unfulfilled" in one place, but "resolved" in another which doesn't make sense. – jib Oct 26 '18 at 19:51
  • Thanks Jib. I edited the question to be more about how to find these cases and not about finding a scan tool. I'm not looking for unhandled rejections but unhandled promises in general. – David Oct 26 '18 at 20:11
  • @CertainPerformance, I do use Flow, but it didn't complain about it for some reason. – David Oct 26 '18 at 20:14

0 Answers0