-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Resolve CA2201: No Reserved Exceptions #47873
Conversation
Thanks for your PR, @dahlbyk. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
283465b
to
4bdd3bf
Compare
src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs
Outdated
Show resolved
Hide resolved
You add it here https://github.com/dotnet/aspnetcore/blob/main/.editorconfig#L80 |
src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs
Outdated
Show resolved
Hide resolved
src/Http/Authentication.Abstractions/src/PublicAPI.Unshipped.txt
Outdated
Show resolved
Hide resolved
src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http3/Http3PendingStream.cs
Outdated
Show resolved
Hide resolved
4bdd3bf
to
095dacc
Compare
Renamed and tried to fix failing tests. |
UnreachableException not available in .NET Standard
All but src/Components/benchmarkapps covered by perf
095dacc
to
4222688
Compare
Ended up just finishing the job and marking CA2201 as an error for production projects. Glad to split into multiple PRs if that's preferred - each commit is meant to be atomic. |
Co-authored-by: Chris Ross <Tratcher@Outlook.com>
@@ -33,7 +33,7 @@ public ConditionCollection(LogicalGrouping grouping, bool trackAllCaptures) | |||
{ | |||
return _conditions[index]; | |||
} | |||
throw new IndexOutOfRangeException($"Cannot access condition at index {index}. Only {_conditions.Count} conditions were captured."); | |||
throw new ArgumentOutOfRangeException(nameof(index), $"Cannot access condition at index {index}. Only {_conditions.Count} conditions were captured."); |
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.
This is another spot where the custom message is good enough that paramName: null
might be preferred.
throw new ArgumentOutOfRangeException(nameof(index), $"Cannot access condition at index {index}. Only {_conditions.Count} conditions were captured."); | |
throw new ArgumentOutOfRangeException(null, $"Cannot access condition at index {index}. Only {_conditions.Count} conditions were captured."); |
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.
I agree that the existing custom message was good here, but how does passing in a null parameter name help? The custom message still gets used with nameof(index)
, right?
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.
how does passing in a null parameter name help?
Non-null
/empty paramName
is appended to the Message
, which adds nothing to this message.
I went ahead and switched to null
.
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.
I missed that you changed this before approving. Can you change it back? I think the slight redundancy in the error message is worth keeping ArgumentOutOfRangeException.ParamName
non-null. Can we change our ArgumentOutOfRange
exceptions to pass in the actualValue
where it makes sense too?
Edit: Never mind. We can do this as a follow up if anyone actually cares.
System.Exception
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.
Looking good! The API proposal for AuthenticationFailureException
was also approved.
.editorconfig
Outdated
@@ -240,6 +240,9 @@ dotnet_diagnostic.CA2016.severity = warning | |||
# CA2200: Rethrow to preserve stack details | |||
dotnet_diagnostic.CA2200.severity = warning | |||
|
|||
# CA2201: Do not raise reserved exception types | |||
dotnet_diagnostic.CA2201.severity = error |
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.
Do we really need to enable this for our test projects? Isn't the addition on line 394 enough? Conversely, if we really do want to enable this for test, do we need line 394?
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.
Do we really need to enable this for our test projects? Isn't the addition on line 394 enough? Conversely, if we really do want to enable this for test, do we need line 394?
This line promotes to warning for all projects, then line 394 demotes back to suggestion for test/perf projects.
@@ -33,7 +33,7 @@ public ConditionCollection(LogicalGrouping grouping, bool trackAllCaptures) | |||
{ | |||
return _conditions[index]; | |||
} | |||
throw new IndexOutOfRangeException($"Cannot access condition at index {index}. Only {_conditions.Count} conditions were captured."); | |||
throw new ArgumentOutOfRangeException(nameof(index), $"Cannot access condition at index {index}. Only {_conditions.Count} conditions were captured."); |
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.
I agree that the existing custom message was good here, but how does passing in a null parameter name help? The custom message still gets used with nameof(index)
, right?
src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs
Outdated
Show resolved
Hide resolved
src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs
Outdated
Show resolved
Hide resolved
src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs
Outdated
Show resolved
Hide resolved
Promote CA2201 to warning (as error)
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.
I believe all feedback has been addressed by the last few commits. Should I rebase onto main
?
.editorconfig
Outdated
@@ -240,6 +240,9 @@ dotnet_diagnostic.CA2016.severity = warning | |||
# CA2200: Rethrow to preserve stack details | |||
dotnet_diagnostic.CA2200.severity = warning | |||
|
|||
# CA2201: Do not raise reserved exception types | |||
dotnet_diagnostic.CA2201.severity = error |
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.
Do we really need to enable this for our test projects? Isn't the addition on line 394 enough? Conversely, if we really do want to enable this for test, do we need line 394?
This line promotes to warning for all projects, then line 394 demotes back to suggestion for test/perf projects.
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. Thanks!
I noticed GitHub didn't add a reference from that issue to this PR or #47708. Might be nice if a collaborator could add a note there about |
Hi @dahlbyk. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Resolve CA2201: No Reserved Exceptions
Progress onResolves Avoid CA2201 (Generic Exception) Violations #47708Microsoft.AspNetCore.Authentication.AuthenticationFailureException
Description
Addresses
initial list from @danmoseleyall the CA2201 errors in published projects.