-
Notifications
You must be signed in to change notification settings - Fork 465
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
Conversation
...tAnalyzers/Core/Microsoft.NetCore.Analyzers/Tasks/DoNotConfigureAwaitWithSuppressThrowing.cs
Outdated
Show resolved
Hide resolved
…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.
2ad880d
to
8045013
Compare
Codecov Report
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
.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)