benaadams / Ben.Demystifier

High performance understanding for stack traces (Make error logs more productive)
Apache License 2.0
2.76k stars 118 forks source link

ArgumentOutOfRange when processing a nested type of a generic type #109

Closed KirillOsenkov closed 1 year ago

KirillOsenkov commented 3 years ago
  String.Substring Line 1282
  TypeNameHelper.GetTypeNameForGenericType Line 65
  ValueTupleResolvedParameter.AppendTypeName Line 23
  ResolvedParameter.Append Line 34
  ResolvedMethod.Append Line 93
  EnhancedStackTrace.Append Line 103
  EnhancedStackTrace.ToString Line 84

The exception is here: https://github.com/benaadams/Ben.Demystifier/blob/0f17b3029b842b0886ce49cafc3032184805873e/src/Ben.Demystifier/TypeNameHelper.cs#L65

The type in question is: Roslyn.Utilities.MultiDictionary2+ValueSet[Microsoft.CodeAnalysis.Document,System.ValueTuple2[Microsoft.CodeAnalysis.ISymbol,Microsoft.CodeAnalysis.FindSymbols.Finders.IReferenceFinder]]

http://sourceroslyn.io/#Microsoft.CodeAnalysis/InternalUtilities/MultiDictionary.cs,b9e522a001545166

Even though the type is a generic type, the name is just ValueSet and doesn't contains the backtick.

KirillOsenkov commented 3 years ago

Here's a PR that adds a unit-test: https://github.com/benaadams/Ben.Demystifier/pull/110

It is significant that the method parameter type is a nested type of a generic type where the generic type parameter is a value tuple with named parameters.

KirillOsenkov commented 3 years ago

Basically the logic for value tuples needs to be aware of nested types of generic types that themselves don't have a backtick in the name: https://github.com/benaadams/Ben.Demystifier/blob/0f17b3029b842b0886ce49cafc3032184805873e/src/Ben.Demystifier/ValueTupleResolvedParameter.cs#L23-L26

benaadams commented 3 years ago

Released a new version that doesn't have this issue; though not sure it makes it a sensible type name, looking into that