Skip to content

Commit ece952a

Browse files
authored
Merge pull request github#7759 from hvitved/csharp/more-debug-context
C#: Add more debug context to various error messages
2 parents d069d91 + ef580aa commit ece952a

File tree

11 files changed

+18
-14
lines changed

11 files changed

+18
-14
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Accessor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public override void Populate(TextWriter trapFile)
4242
var prop = PropertySymbol;
4343
if (prop is null)
4444
{
45-
Context.ModelError(Symbol, "Unhandled accessor associated symbol");
45+
var type = Symbol.AssociatedSymbol?.GetType().ToString() ?? "null";
46+
Context.ModelError(Symbol, $"Unhandled accessor associated symbol of type {type}");
4647
return;
4748
}
4849

@@ -61,7 +62,7 @@ public override void Populate(TextWriter trapFile)
6162
}
6263
else
6364
{
64-
Context.ModelError(Symbol, "Unhandled accessor kind");
65+
Context.ModelError(Symbol, $"Unhandled accessor method {Symbol.ToDisplayString()}");
6566
return;
6667
}
6768

csharp/extractor/Semmle.Extraction.CSharp/Entities/EventAccessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public override void Populate(TextWriter trapFile)
2121
var @event = EventSymbol;
2222
if (@event is null)
2323
{
24-
Context.ModelError(Symbol, "Unhandled event accessor associated symbol");
24+
var type = Symbol.AssociatedSymbol?.GetType().ToString() ?? "null";
25+
Context.ModelError(Symbol, $"Unhandled event accessor associated symbol of type {type}");
2526
return;
2627
}
2728

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Lambda.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private Lambda(ExpressionNodeInfo info, CSharpSyntaxNode body, IEnumerable<Param
4545
else if (body is BlockSyntax blockBody)
4646
Statements.Block.Create(Context, blockBody, this, 0);
4747
else
48-
Context.ModelError(body, "Unhandled lambda body");
48+
Context.ModelError(body, $"Unhandled lambda body of type {body.GetType()}");
4949
});
5050
}
5151

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/MemberAccess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private static Expression Create(ExpressionNodeInfo info, ExpressionSyntax expre
9696
kind = ExprKind.NAMESPACE_ACCESS;
9797
break;
9898
default:
99-
info.Context.ModelError(info.Node, "Unhandled symbol for member access");
99+
info.Context.ModelError(info.Node, $"Unhandled symbol for member access of kind {symbol.Kind}");
100100
kind = ExprKind.UNKNOWN;
101101
break;
102102
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ObjectCreation/BaseObjectCreation.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ protected override void PopulateExpression(TextWriter trapFile)
4343

4444
if (Syntax.Initializer is not null)
4545
{
46-
switch (Syntax.Initializer.Kind())
46+
var kind = Syntax.Initializer.Kind();
47+
switch (kind)
4748
{
4849
case SyntaxKind.CollectionInitializerExpression:
4950
CollectionInitializer.Create(new ExpressionNodeInfo(Context, Syntax.Initializer, this, -1).SetType(Type));
@@ -52,7 +53,7 @@ protected override void PopulateExpression(TextWriter trapFile)
5253
ObjectInitializer.Create(new ExpressionNodeInfo(Context, Syntax.Initializer, this, -1).SetType(Type));
5354
break;
5455
default:
55-
Context.ModelError(Syntax.Initializer, "Unhandled initializer in object creation");
56+
Context.ModelError(Syntax.Initializer, $"Unhandled initializer in object creation of kind {kind}");
5657
break;
5758
}
5859
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Patterns/Pattern.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ internal static Expression Create(Context cx, PatternSyntax syntax, IExpressionP
6868
case DiscardDesignationSyntax discard:
6969
return new Expressions.Discard(cx, discard, parent, child);
7070
default:
71-
throw new InternalError("var pattern designation is unhandled");
71+
throw new InternalError($"var pattern designation of type {varPattern.Designation.GetType()} is unhandled");
7272
}
7373

7474
case DiscardPatternSyntax dp:

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public static Expression CreateParenthesized(Context cx, VarPatternSyntax varPat
105105
}
106106
break;
107107
default:
108-
throw new InternalError(variable, "Unhandled designation type");
108+
var type = variable.GetType().ToString() ?? "null";
109+
throw new InternalError(variable, $"Unhandled designation type {type}");
109110
}
110111

111112
elementTypes.Add(sub.Type.HasValue && sub.Type.Value.Symbol?.Kind != SymbolKind.ErrorType

csharp/extractor/Semmle.Extraction.CSharp/Entities/PreprocessorDirectives/LineDirective.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private LineDirective(Context cx, LineDirectiveTriviaSyntax trivia)
1313
SyntaxKind.DefaultKeyword => LineDirectiveKind.Default,
1414
SyntaxKind.HiddenKeyword => LineDirectiveKind.Hidden,
1515
SyntaxKind.NumericLiteralToken => LineDirectiveKind.Numeric,
16-
_ => throw new InternalError(trivia, "Unhandled line token kind")
16+
_ => throw new InternalError(trivia, $"Unhandled line token kind {trivia.Line.Kind()}")
1717
})
1818
{
1919
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/PreprocessorDirectives/NullableDirective.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ protected override void PopulatePreprocessor(TextWriter trapFile)
1818
SyntaxKind.DisableKeyword => 0,
1919
SyntaxKind.EnableKeyword => 1,
2020
SyntaxKind.RestoreKeyword => 2,
21-
_ => throw new InternalError(Symbol, "Unhandled setting token kind")
21+
_ => throw new InternalError(Symbol, $"Unhandled setting token kind {Symbol.SettingToken.Kind()}")
2222
};
2323

2424
var target = Symbol.TargetToken.Kind() switch
2525
{
2626
SyntaxKind.None => 0,
2727
SyntaxKind.AnnotationsKeyword => 1,
2828
SyntaxKind.WarningsKeyword => 2,
29-
_ => throw new InternalError(Symbol, "Unhandled target token kind")
29+
_ => throw new InternalError(Symbol, $"Unhandled target token kind {Symbol.TargetToken.Kind()}")
3030
};
3131

3232
trapFile.directive_nullables(this, setting, target);

csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/Case.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static Statement Create(Context cx, SwitchLabelSyntax node, Switch parent
2323
case SyntaxKind.CasePatternSwitchLabel:
2424
return CasePattern.Create(cx, (CasePatternSwitchLabelSyntax)node, parent, child);
2525
default:
26-
throw new InternalError(node, "Unhandled case label");
26+
throw new InternalError(node, $"Unhandled case label of kind {node.Kind()}");
2727
}
2828
}
2929
}

0 commit comments

Comments
 (0)