elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.58k stars 8.21k forks source link

Enable @typescript-eslint/return-await lint rule #118550

Open mshustov opened 2 years ago

mshustov commented 2 years ago

Kibana server code is transpiled into the environment with native async/await support. Although, we don't enforce async/await usage for asynchronous code, which comes at the code of losing async error stack trace in the case of an exception:

When an error occurs, whether from a synchronous or asynchronous flow, it's imperative to have a full stacktrace of the error flow.
Surprisingly, if an async function returns a promise (e.g., calls other async function) without awaiting, should an error occur then the caller function won't appear in the stacktrace.
This will leave the person who diagnoses the error with partial information - All the more if the error cause lies within that caller function.
There is a feature v8 called "zero-cost async stacktraces" that allow stacktraces not to be cut on the most recent await.
But due to non-trivial implementation details, it will not work if the return value of a function (sync or async) is a promise.
So, to avoid holes in stacktraces when returned promises would be rejected, we must always explicitly resolve promises with await before returning them from functions

Source

Enforcing a promise to be awaited before a return statement via @typescript-eslint/return-await` linting rule, improves Developer experience by making it easier to find where the exception was thrown.

elasticmachine commented 2 years ago

Pinging @elastic/kibana-core (Team:Core)

elasticmachine commented 2 years ago

Pinging @elastic/kibana-operations (Team:Operations)

tylersmalley commented 2 years ago

Blocked by https://github.com/elastic/kibana-operations/issues/218. We will need to enable this per-package as there are a massive amount of violations at this point.