Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: no-floating-promises #1780

Merged
merged 4 commits into from
Apr 13, 2021

Conversation

naseemkullah
Copy link
Member

Signed-off-by: Naseem [email protected]

Which problem is this PR solving?

Short description of the changes

It was mostly tests that had floating promises (if there's been any test flakiness it could possibly be attributed to that), but there were a few floating promises in non-test code.

@naseemkullah
Copy link
Member Author

naseemkullah commented Dec 23, 2020

You'll want to ignore white spaces when reviewing this one.

@naseemkullah naseemkullah force-pushed the no-floating-promises branch 2 times, most recently from 3eb6ef5 to 0acecb3 Compare December 23, 2020 11:43
@obecny
Copy link
Member

obecny commented Dec 29, 2020

I guess in many cases it would be enough to add catch instead of changing this from promise to async. It looks like you are replacing the promises with async whereas the problem was to ensure there are no floating promises. The number of changes are also much bigger because of that. Any reason to change it from promise to async ?

@naseemkullah
Copy link
Member Author

naseemkullah commented Dec 29, 2020

I guess in many cases it would be enough to add catch instead of changing this from promise to catch. It looks like you are replacing the promises with async whereas the problem was to ensure there are no floating promises. The number of changes are also much bigger because of that. Any reason to change it from promise to async ?

Yeah good point, the only reason was my preference for async/await syntax but this does make the review process more cumbersome, I will revert those if that is preferred.

@naseemkullah naseemkullah force-pushed the no-floating-promises branch 2 times, most recently from d0bc121 to 3a45f3c Compare January 4, 2021 01:15
@naseemkullah
Copy link
Member Author

naseemkullah commented Jan 4, 2021

I've made the rule warn in the test files where there are many floating promises, we can address these incrementally one (or more) test file(s) at a time in subsequent PRs.

@codecov
Copy link

codecov bot commented Jan 4, 2021

Codecov Report

Merging #1780 (34a7bf9) into main (e27f9fb) will decrease coverage by 0.01%.
The diff coverage is 50.00%.

❗ Current head 34a7bf9 differs from pull request most recent head 075469a. Consider uploading reports for the commit 075469a to get more accurate results

@@            Coverage Diff             @@
##             main    #1780      +/-   ##
==========================================
- Coverage   92.75%   92.73%   -0.02%     
==========================================
  Files         138      138              
  Lines        4927     4928       +1     
  Branches     1017     1017              
==========================================
  Hits         4570     4570              
- Misses        357      358       +1     
Impacted Files Coverage Δ
...ges/opentelemetry-metrics/src/export/Controller.ts 76.00% <0.00%> (-3.17%) ⬇️
...telemetry-tracing/src/export/BatchSpanProcessor.ts 91.20% <100.00%> (ø)

@dyladan
Copy link
Member

dyladan commented Jan 4, 2021

I guess in many cases it would be enough to add catch instead of changing this from promise to catch. It looks like you are replacing the promises with async whereas the problem was to ensure there are no floating promises. The number of changes are also much bigger because of that. Any reason to change it from promise to async ?

Yeah good point, the only reason was my preference for async/await syntax but this does make the review process more cumbersome, I will revert those if that is preferred.

It is worth noting that the async/await syntax severely bloats the output size of the js. This is ok on the node side, but for the core modules and web modules it is something we need to consider.

@obecny
Copy link
Member

obecny commented Jan 4, 2021

instead of // eslint-disable-next-line @typescript-eslint/no-floating-promises I think you could either use some console logger with default log option or perhaps our global error handler ?

Base automatically changed from master to main January 25, 2021 19:26
@naseemkullah
Copy link
Member Author

instead of // eslint-disable-next-line @typescript-eslint/no-floating-promises I think you could either use some console logger with default log option or perhaps our global error handler ?

I should probably know this but what is our global error handler? diag.error() ?

@rauno56
Copy link
Member

rauno56 commented Mar 17, 2021

It is worth noting that the async/await syntax severely bloats the output size of the js. This is ok on the node side, but for the core modules and web modules it is something we need to consider.

I guess the bloat comes from the transpilation step, right?
Promises(and async/await, although probably a little bit less so) are widely supported everywhere except IE 11. Have we considered turning transpiling promises and/or async/await off altogether?

@dyladan
Copy link
Member

dyladan commented Apr 12, 2021

instead of // eslint-disable-next-line @typescript-eslint/no-floating-promises I think you could either use some console logger with default log option or perhaps our global error handler ?

I should probably know this but what is our global error handler? diag.error() ?

There are 2 ways to handle errors. diag.error() will log them to whatever configured logger. There is also a global error handler which is called in cases where we would normally throw ourselves but prefer to have the user handle it. By default, it calls diag.error().

Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me pending the breaking lint step

Only warn in tests, disable rule for existing occurences in
non-test modules.

Signed-off-by: naseemkullah <[email protected]>
Signed-off-by: naseemkullah <[email protected]>
@naseemkullah
Copy link
Member Author

Ok, this is ready to go now. As mentioned we will tackle tests separately (the rule only emits a warning for tests until they are taken care of at which point we can enforce it).

Signed-off-by: naseemkullah <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants