CA2208 Instantiate argument exceptions correctly#58768
Conversation
| WriteLine("' <auto-generated />"); break; | ||
| default: | ||
| throw new ArgumentException("Unexpected target language", nameof(_targetLang)); | ||
| throw new InvalidOperationException($"Unexpected target language: '{_targetLang}'"); |
There was a problem hiding this comment.
I'm not sure if ExceptionUtilities.Unreachable is more suitable?
There was a problem hiding this comment.
Thank you, I will make use of that.
There was a problem hiding this comment.
If ExceptionUtilities.UnexpectedValue is available here that might be good to use.
There was a problem hiding this comment.
if it isn't available, is it okay to add a using?
There was a problem hiding this comment.
If just adding using Roslyn.Utilities; makes it available, then it's fine to use it.
Youssef1313
left a comment
There was a problem hiding this comment.
I don't see the occurrences in the build error for dotnet/msbuild#7187 are fixed here.
/home/vsts/.nuget/packages/microsoft.codeanalysis.collections/4.0.0-4.21379.20/contentFiles/cs/netstandard2.0/ImmutableSegmentedList`1.cs(346,23): error CA2208: (NETCORE_ENGINEERING_TELEMETRY=Build) Call the ArgumentException constructor that contains a message and/or paramName parameter
/home/vsts/.nuget/packages/microsoft.codeanalysis.collections/4.0.0-4.21379.20/contentFiles/cs/netstandard2.0/ImmutableSegmentedList`1+ValueBuilder.cs(249,27): error CA2208: (NETCORE_ENGINEERING_TELEMETRY=Build) Call the ArgumentException constructor that contains a message and/or paramName parameter
Thanks, I am currently working through each of the problems. There are quite a few and I have a feeling some changes might break things. It might be easier if I only fix those things affecting MSBuild. |
| # Instantiate argument exceptions correctly | ||
| dotnet_diagnostic.CA2208.severity = warning | ||
|
|
There was a problem hiding this comment.
This could move to Shipping.globalconfig to limit the analysis scope.
| public override MessageID MessageID { get { return MessageID.IDS_FeatureQueryExpression; } } // TODO: what is the correct ID here? | ||
| public override Location ParameterLocation(int index) { return _parameters[index].Locations[0]; } | ||
| public override TypeWithAnnotations ParameterTypeWithAnnotations(int index) { throw new ArgumentException(); } // implicitly typed | ||
| public override TypeWithAnnotations ParameterTypeWithAnnotations(int index) { throw new ArgumentException(null, nameof(index)); } // implicitly typed |
Fixes #45286
Blocking dotnet/msbuild#7187