owid-grapher icon indicating copy to clipboard operation
owid-grapher copied to clipboard

🔨 set up eslint rule to error on dangling promises + fix 245 violations

Open danyx23 opened this issue 2 years ago • 1 comments

With the introduction of a more rigorous use of transactions, dangling promises have become more problematic. It used to the be the case that if a promise was not awaited in an api route handler, node would just wait for it to complete. But since we now open transaction scopes in the route handlers, it can happen that a the router handler finishes and closes a transaction and then the dangling promise continues and tries to access the db via that transaction which then leads to an error and crashes the admin.

This PR enables an ESLint rule that makes unhandled promises an error. You can either await the result, or, for cases where you genuinely do not need to await the promise, mark the promise as intentionally not awaited by prefixing it with the JS void operator.

This PR then fixes all the ~250 places that this eslint rule complained about

danyx23 avatar Mar 16 '24 13:03 danyx23

  • #3396 Graphite
  • #3391 Graphite
  • #3385 Graphite
  • #3360 Graphite
  • #3359 Graphite
  • #3358 Graphite 👈
  • #3299 Graphite: 1 other dependent PR (#3372 Graphite)
  • #3298 Graphite
  • #3293 Graphite
  • #3292 Graphite
  • #3271 Graphite
  • #3259 Graphite
  • #3258 Graphite
  • master

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @danyx23 and the rest of your teammates on Graphite Graphite

danyx23 avatar Mar 16 '24 13:03 danyx23

Merge activity

  • Mar 26, 10:04 AM EDT: @danyx23 started a stack merge that includes this pull request via Graphite.
  • Mar 26, 10:19 AM EDT: Graphite rebased this pull request as part of a merge.
  • Mar 26, 10:22 AM EDT: @danyx23 merged this pull request with Graphite.

danyx23 avatar Mar 26 '24 14:03 danyx23