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

Add analyzer to detect use of Task<T>.ConfigureAwait with ConfigureAwaitOptions.SuppressThrowing #6669

Merged
merged 1 commit into from
Jun 28, 2023

Conversation

stephentoub
Copy link
Member

.NET 8 introduces new overloads of ConfigureAwait. One of the options is SuppressThrowing, but it's not supported by Task<T>, since that would then lead to returning a possibly invalid T. This rule flags use of SuppressThrowing so that you get a build-time rather than execution-time error.

Contributes to dotnet/runtime#22144 (comment)

@stephentoub stephentoub requested a review from a team as a code owner June 5, 2023 21:42
…aitOptions.SuppressThrowing

.NET 8 introduces new overloads of ConfigureAwait.  One of the options is SuppressThrowing, but it's not supported by `Task<T>`, since that would then lead to returning a possibly invalid T.  This rule flags use of SuppressThrowing so that you get a build-time rather than execution-time error.
@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Merging #6669 (8045013) into main (2b6ab8d) will decrease coverage by 0.01%.
The diff coverage is 97.29%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6669      +/-   ##
==========================================
- Coverage   96.40%   96.39%   -0.01%     
==========================================
  Files        1379     1381       +2     
  Lines      322253   322401     +148     
  Branches    10460    10463       +3     
==========================================
+ Hits       310657   310794     +137     
- Misses       9103     9112       +9     
- Partials     2493     2495       +2     

@stephentoub stephentoub requested a review from buyaa-n June 6, 2023 20:12
Copy link
Member

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

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

LGTM

@stephentoub stephentoub merged commit 0bcd02b into dotnet:main Jun 28, 2023
@stephentoub stephentoub deleted the configureawaitoptions branch June 28, 2023 00:09
@@ -4,6 +4,7 @@

Rule ID | Category | Severity | Notes
--------|----------|----------|-------
CA2261 | Usage | Warning | DoNotUseConfigureAwaitWithSuppressThrowing, [Documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2250)
Copy link

@StephenCleary StephenCleary Nov 3, 2023

Choose a reason for hiding this comment

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

Should this be https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2261 ?

I believe this is the equivalent line in main:

CA2261 | Usage | Warning | DoNotUseConfigureAwaitWithSuppressThrowing, [Documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2250)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. No idea how it ended up like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants