Skip to content

Invalid attribute arguments break the generator and cause multiple Roslyn service crashes in VS #2183

@Rekkonnect

Description

@Rekkonnect

The generator completely crashes when an invalid argument is provided in any of the generator-driven attributes. In my example, just a bad nameof panics the entire flow, with the following error dump on any of the internal error warnings in VS.

StreamJsonRpc.RemoteInvocationException: Index was outside the bounds of the array.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__156`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
      at TUnit.Core.SourceGenerator.CodeGenerators.Helpers.MethodDataSourceRetriever.<>c__DisplayClass0_0.<ParseMethodData>b__0(IMethodSymbol x)
      at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
      at TUnit.Core.SourceGenerator.CodeGenerators.Helpers.MethodDataSourceRetriever.ParseMethodData(GeneratorAttributeSyntaxContext context, ImmutableArray`1 parameterOrPropertyTypes, INamedTypeSymbol namedTypeSymbol, AttributeData methodDataAttribute, ArgumentsType argumentsType, Int32 index)
      at TUnit.Core.SourceGenerator.CodeGenerators.Helpers.ArgumentsRetriever.GetArguments(GeneratorAttributeSyntaxContext context, ImmutableArray`1 parameters, IPropertySymbol property, ImmutableArray`1 parameterOrPropertyTypes, ImmutableArray`1 dataAttributes, INamedTypeSymbol testClass, IMethodSymbol testMethod, ArgumentsType argumentsType, String propertyName)+MoveNext()
      at TUnit.Core.SourceGenerator.CodeGenerators.Helpers.TestSourceDataModelRetriever.ParseTestDatas(IMethodSymbol methodSymbol, GeneratorAttributeSyntaxContext context, INamedTypeSymbol namedTypeSymbol)+MoveNext()
[... manually truncated]

A quick example of a break:

    [Test]
    [MethodDataSource(nameof())]
    public async Task TestDocumentCharacterCount(
        DocumentCharacterCountTestCase testCase)
    {
    }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions