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.

Warn when `await` keyword might be missing

See original GitHub issue

Picking up https://github.com/babel/babel-eslint/issues/593 and https://github.com/eslint/eslint/issues/9787

Some of the meanest kinds of bugs we are running into are race conditions happening at runtime because of accidentally missing await statements.

Others run in this, too. Quoting @aymericbouzy:

My real pain point is the following: I have a large codebase, and when my code runs, I encounter bugs that are difficult to reproduce, unpredictable results … simply because I forgot to await a promise. Here is a simple example where not awaiting a promise leads to bad results:

(https://github.com/eslint/eslint/issues/9787#issuecomment-367264702)

Now, I think we already know that ESLint cannot reliably detect these errors. I think that @ljharb is right with this statement:

This is what a type system and/or tests are for; this just isn’t a lintable problem.

But in practice I often times find myself in a situation where the type system doesn’t catch the problem either or where the effort to make it detect the problem would simply be quite large.

Pragmatically, a simple warning when an await keyword might be missing would do wonders.

Then I can still decide if that’s the case or not.

What do you think?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
kaicataldocommented, Aug 14, 2020

To clarify, it sounds like you’re suggesting a rule that would warn on all function calls found in an async function body that are not awaited. Is that right?

If so, I don’t think this should be a rule in core. I also don’t think this is a particularly helpful rule in general, because I’ve never encountered a codebase where all function calls are asynchronous. This means that there would be a lot of false positives and negatives, and would most likely produce a lot of useless warnings. In my experience, this leads to people ignoring the warning altogether.

I’m a bit confused as to why a type system isn’t helping you here. In my experience with TypeScript, at least, these kinds of errors have been caught.

1reaction
ljharbcommented, Aug 15, 2020

Without a type system, that’s just not possible in the most common case, which is when the other async function is in another file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rule proposal: Warn when await keyword might be missing
This was previously proposed as an eslint feature, and rejected because: Without a type system, that's just not possible in the most common ......
Read more >
How to detect missing await statement? - javascript
A unit test which runs the code would likely see if an await keyword should be added. One of the first results when...
Read more >
Detect missing await in TypeScript - Meziantou's blog
Even when you don't await a promise, the ts file is perfectly valid, so the TypeScript compiler can compile without error.
Read more >
Code Inspection: Missing await for an async function call
Reports an async function call without an expected await prefix inside an async function. Such call returns a Promise and control flow is...
Read more >
Don't get burned by missing await Calls for Async Code in ...
or in the warning list: So the tooling can help avoid this error and in most cases that's probably a pretty obvious catch....
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