Skip to content

Commit 353d43a

Browse files
committed
Log model errors even in standalone extraction
1 parent 5149ffd commit 353d43a

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

csharp/extractor/Semmle.Extraction/Context.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,27 @@ private void ExtractionError(Message msg)
376376
Extractor.Message(msg);
377377
}
378378

379+
private void ExtractionError(InternalError error)
380+
{
381+
ExtractionError(new Message(error.Message, error.EntityText, CreateLocation(error.Location), error.StackTrace, Severity.Error));
382+
}
383+
384+
private void ReportError(InternalError error)
385+
{
386+
if (!Extractor.Standalone)
387+
throw error;
388+
389+
ExtractionError(error);
390+
}
391+
379392
/// <summary>
380393
/// Signal an error in the program model.
381394
/// </summary>
382395
/// <param name="node">The syntax node causing the failure.</param>
383396
/// <param name="msg">The error message.</param>
384397
public void ModelError(SyntaxNode node, string msg)
385398
{
386-
if (!Extractor.Standalone)
387-
throw new InternalError(node, msg);
399+
ReportError(new InternalError(node, msg));
388400
}
389401

390402
/// <summary>
@@ -394,8 +406,7 @@ public void ModelError(SyntaxNode node, string msg)
394406
/// <param name="msg">The error message.</param>
395407
public void ModelError(ISymbol symbol, string msg)
396408
{
397-
if (!Extractor.Standalone)
398-
throw new InternalError(symbol, msg);
409+
ReportError(new InternalError(symbol, msg));
399410
}
400411

401412
/// <summary>
@@ -404,8 +415,7 @@ public void ModelError(ISymbol symbol, string msg)
404415
/// <param name="msg">The error message.</param>
405416
public void ModelError(string msg)
406417
{
407-
if (!Extractor.Standalone)
408-
throw new InternalError(msg);
418+
ReportError(new InternalError(msg));
409419
}
410420

411421
/// <summary>

csharp/ql/src/Diagnostics/DiagnosticExtractionErrors.ql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111
import csharp
1212
import semmle.code.csharp.commons.Diagnostics
1313

14+
private string getLocation(ExtractorError error) {
15+
if error.getLocation().getFile().fromSource()
16+
then result = " in " + error.getLocation().getFile()
17+
else result = ""
18+
}
19+
1420
from ExtractorError error
1521
where not exists(CompilerError ce | ce.getLocation().getFile() = error.getLocation().getFile())
1622
select error,
17-
"Unexpected " + error.getOrigin() + " error: " + error.getText() + " in " +
18-
error.getLocation().getFile(), 3
23+
"Unexpected " + error.getOrigin() + " error" + getLocation(error) + ": " + error.getText(), 3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| 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 |
2+
| file://:0:0:0:0 | Unhandled literal type | Unexpected C# extractor error: Unhandled literal type | 3 |

0 commit comments

Comments
 (0)