Log model errors even in standalone extraction

This commit is contained in:
Tamas Vajk
2021-04-21 12:38:55 +02:00
parent 5149ffdd16
commit 353d43a039
3 changed files with 25 additions and 8 deletions

View File

@@ -376,6 +376,19 @@ namespace Semmle.Extraction
Extractor.Message(msg);
}
private void ExtractionError(InternalError error)
{
ExtractionError(new Message(error.Message, error.EntityText, CreateLocation(error.Location), error.StackTrace, Severity.Error));
}
private void ReportError(InternalError error)
{
if (!Extractor.Standalone)
throw error;
ExtractionError(error);
}
/// <summary>
/// Signal an error in the program model.
/// </summary>
@@ -383,8 +396,7 @@ namespace Semmle.Extraction
/// <param name="msg">The error message.</param>
public void ModelError(SyntaxNode node, string msg)
{
if (!Extractor.Standalone)
throw new InternalError(node, msg);
ReportError(new InternalError(node, msg));
}
/// <summary>
@@ -394,8 +406,7 @@ namespace Semmle.Extraction
/// <param name="msg">The error message.</param>
public void ModelError(ISymbol symbol, string msg)
{
if (!Extractor.Standalone)
throw new InternalError(symbol, msg);
ReportError(new InternalError(symbol, msg));
}
/// <summary>
@@ -404,8 +415,7 @@ namespace Semmle.Extraction
/// <param name="msg">The error message.</param>
public void ModelError(string msg)
{
if (!Extractor.Standalone)
throw new InternalError(msg);
ReportError(new InternalError(msg));
}
/// <summary>

View File

@@ -11,8 +11,13 @@
import csharp
import semmle.code.csharp.commons.Diagnostics
private string getLocation(ExtractorError error) {
if error.getLocation().getFile().fromSource()
then result = " in " + error.getLocation().getFile()
else result = ""
}
from ExtractorError error
where not exists(CompilerError ce | ce.getLocation().getFile() = error.getLocation().getFile())
select error,
"Unexpected " + error.getOrigin() + " error: " + error.getText() + " in " +
error.getLocation().getFile(), 3
"Unexpected " + error.getOrigin() + " error" + getLocation(error) + ": " + error.getText(), 3

View File

@@ -0,0 +1,2 @@
| Program.cs:9:32:9:46 | Unable to resolve target for call. (Compilation error?) | Unexpected C# extractor error in Program.cs: Unable to resolve target for call. (Compilation error?) | 3 |
| file://:0:0:0:0 | Unhandled literal type | Unexpected C# extractor error: Unhandled literal type | 3 |