Merge pull request #7759 from hvitved/csharp/more-debug-context

C#: Add more debug context to various error messages
This commit is contained in:
Tom Hvitved
2022-01-27 09:40:21 +01:00
committed by GitHub
11 changed files with 18 additions and 14 deletions

View File

@@ -42,7 +42,8 @@ namespace Semmle.Extraction.CSharp.Entities
var prop = PropertySymbol;
if (prop is null)
{
Context.ModelError(Symbol, "Unhandled accessor associated symbol");
var type = Symbol.AssociatedSymbol?.GetType().ToString() ?? "null";
Context.ModelError(Symbol, $"Unhandled accessor associated symbol of type {type}");
return;
}
@@ -61,7 +62,7 @@ namespace Semmle.Extraction.CSharp.Entities
}
else
{
Context.ModelError(Symbol, "Unhandled accessor kind");
Context.ModelError(Symbol, $"Unhandled accessor method {Symbol.ToDisplayString()}");
return;
}

View File

@@ -21,7 +21,8 @@ namespace Semmle.Extraction.CSharp.Entities
var @event = EventSymbol;
if (@event is null)
{
Context.ModelError(Symbol, "Unhandled event accessor associated symbol");
var type = Symbol.AssociatedSymbol?.GetType().ToString() ?? "null";
Context.ModelError(Symbol, $"Unhandled event accessor associated symbol of type {type}");
return;
}

View File

@@ -45,7 +45,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
else if (body is BlockSyntax blockBody)
Statements.Block.Create(Context, blockBody, this, 0);
else
Context.ModelError(body, "Unhandled lambda body");
Context.ModelError(body, $"Unhandled lambda body of type {body.GetType()}");
});
}

View File

@@ -96,7 +96,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
kind = ExprKind.NAMESPACE_ACCESS;
break;
default:
info.Context.ModelError(info.Node, "Unhandled symbol for member access");
info.Context.ModelError(info.Node, $"Unhandled symbol for member access of kind {symbol.Kind}");
kind = ExprKind.UNKNOWN;
break;
}

View File

@@ -43,7 +43,8 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
if (Syntax.Initializer is not null)
{
switch (Syntax.Initializer.Kind())
var kind = Syntax.Initializer.Kind();
switch (kind)
{
case SyntaxKind.CollectionInitializerExpression:
CollectionInitializer.Create(new ExpressionNodeInfo(Context, Syntax.Initializer, this, -1).SetType(Type));
@@ -52,7 +53,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
ObjectInitializer.Create(new ExpressionNodeInfo(Context, Syntax.Initializer, this, -1).SetType(Type));
break;
default:
Context.ModelError(Syntax.Initializer, "Unhandled initializer in object creation");
Context.ModelError(Syntax.Initializer, $"Unhandled initializer in object creation of kind {kind}");
break;
}
}

View File

@@ -68,7 +68,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
case DiscardDesignationSyntax discard:
return new Expressions.Discard(cx, discard, parent, child);
default:
throw new InternalError("var pattern designation is unhandled");
throw new InternalError($"var pattern designation of type {varPattern.Designation.GetType()} is unhandled");
}
case DiscardPatternSyntax dp:

View File

@@ -105,7 +105,8 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
}
break;
default:
throw new InternalError(variable, "Unhandled designation type");
var type = variable.GetType().ToString() ?? "null";
throw new InternalError(variable, $"Unhandled designation type {type}");
}
elementTypes.Add(sub.Type.HasValue && sub.Type.Value.Symbol?.Kind != SymbolKind.ErrorType

View File

@@ -13,7 +13,7 @@ namespace Semmle.Extraction.CSharp.Entities
SyntaxKind.DefaultKeyword => LineDirectiveKind.Default,
SyntaxKind.HiddenKeyword => LineDirectiveKind.Hidden,
SyntaxKind.NumericLiteralToken => LineDirectiveKind.Numeric,
_ => throw new InternalError(trivia, "Unhandled line token kind")
_ => throw new InternalError(trivia, $"Unhandled line token kind {trivia.Line.Kind()}")
})
{
}

View File

@@ -18,7 +18,7 @@ namespace Semmle.Extraction.CSharp.Entities
SyntaxKind.DisableKeyword => 0,
SyntaxKind.EnableKeyword => 1,
SyntaxKind.RestoreKeyword => 2,
_ => throw new InternalError(Symbol, "Unhandled setting token kind")
_ => throw new InternalError(Symbol, $"Unhandled setting token kind {Symbol.SettingToken.Kind()}")
};
var target = Symbol.TargetToken.Kind() switch
@@ -26,7 +26,7 @@ namespace Semmle.Extraction.CSharp.Entities
SyntaxKind.None => 0,
SyntaxKind.AnnotationsKeyword => 1,
SyntaxKind.WarningsKeyword => 2,
_ => throw new InternalError(Symbol, "Unhandled target token kind")
_ => throw new InternalError(Symbol, $"Unhandled target token kind {Symbol.TargetToken.Kind()}")
};
trapFile.directive_nullables(this, setting, target);

View File

@@ -23,7 +23,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
case SyntaxKind.CasePatternSwitchLabel:
return CasePattern.Create(cx, (CasePatternSwitchLabelSyntax)node, parent, child);
default:
throw new InternalError(node, "Unhandled case label");
throw new InternalError(node, $"Unhandled case label of kind {node.Kind()}");
}
}
}

View File

@@ -36,7 +36,7 @@ namespace Semmle.Extraction.CSharp.Populators
public override void DefaultVisit(SyntaxNode node)
{
throw new InternalError(node, "Unhandled top-level syntax node");
throw new InternalError(node, $"Unhandled top-level syntax node of type {node.GetType()}");
}
public override void VisitGlobalStatement(GlobalStatementSyntax node)