Skip to content

Commit ce0ca38

Browse files
authored
Improve Exception with context (#1039)
1 parent f02b74f commit ce0ca38

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/generators/Silk.NET.SilkTouch.Symbols/SymbolVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ protected virtual TypeReference VisitTypeReference(TypeReference typeReference)
118118
{
119119
if (typeReference is ExternalTypeReference etr) return VisitExternalTypeReference(etr);
120120
if (typeReference is InternalTypeReference itr) return VisitInternalTypeReference(itr);
121-
if (typeReference is UnresolvedTypeReference utr) UnresolvedTypeReference.ThrowInvalidSymbol();
121+
if (typeReference is UnresolvedTypeReference utr) UnresolvedTypeReference.ThrowInvalidSymbol(utr);
122122
if (typeReference is PointerTypeReference ptr) return VisitPointerTypeReference(ptr);
123123
if (typeReference is FunctionPointerTypeReference fptr) return VisitFunctionPointerTypeReference(fptr);
124124
return ThrowUnknownSymbol<TypeReference>(typeReference);

src/generators/Silk.NET.SilkTouch.Symbols/UnresolvedTypeReference.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ public sealed record UnresolvedTypeReference(string Text) : TypeReference
1414
/// Throw helper to use when encountering <see cref="UnresolvedTypeReference"/> when type resolution should've already happened.
1515
/// </summary>
1616
/// <exception cref="InvalidOperationException"></exception>
17-
public static void ThrowInvalidSymbol()
17+
public static void ThrowInvalidSymbol(UnresolvedTypeReference utr)
1818
{
19+
// This is by far the most common exception during generation, so make sure it's useful!!
1920
throw new InvalidOperationException
20-
($"Visited {nameof(UnresolvedTypeReference)}, but type resolution should have already happened.");
21+
(
22+
$"Visited {nameof(UnresolvedTypeReference)}, but type resolution should have already happened. Text: \"{utr.Text}\""
23+
);
2124
}
2225
}

0 commit comments

Comments
 (0)