TUnit icon indicating copy to clipboard operation
TUnit copied to clipboard

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

Open Rekkonnect opened this issue 8 months ago • 4 comments

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)
    {
    }

Rekkonnect avatar Mar 29 '25 10:03 Rekkonnect

Does an empty nameof compile?

thomhurst avatar Mar 29 '25 11:03 thomhurst

No, but it only yields an error without causing service crashes. When this is applied to any of the analyzed attributes, multiple Roslyn service crash warnings popup, text fizzles, and it seems impossible to recover without restarting VS.

Rekkonnect avatar Mar 29 '25 11:03 Rekkonnect

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Apr 29 '25 00:04 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar May 04 '25 00:05 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jun 04 '25 00:06 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jul 06 '25 00:07 github-actions[bot]