Always await expression of promise type in return position #27573
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #27544
Currently, if a promise handler that is itself returning a promise is changed to an async function using our code fix, that promise is not awaited if it will be in a return position in the resulting async function. This was done since the following are equivalent in evaluation:
However, if a rejected promise is returned from within a
try
block, awaiting the promise will cause it to be caught by thecatch
block, whereas returning it without an await will pass the rejected promise to the caller.This PR changes the code fix behavior so promises returned by promise handlers will always be awaited, regardless of whether they are in a return position or not. This does mean that "unnecessary" awaits will be added, but for promises that might potentially be rejected but are, at the time of the code fix, not caught, the extra await may avoid later issues if wrapped in a
catch
after the fact.Thanks @bterlson for input!