Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 343cddc

Browse files
committed
C#: Refactor extractor errors and log extractor errors to the database.
1 parent e1158bb commit 343cddc

41 files changed

Lines changed: 365 additions & 192 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

csharp/extractor/Semmle.Extraction.CIL/Entities/Assembly.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using Semmle.Util.Logging;
55
using System;
6+
using Semmle.Extraction.Entities;
67

78
namespace Semmle.Extraction.CIL.Entities
89
{
@@ -70,12 +71,7 @@ public override IEnumerable<IExtractionProduct> Contents
7071
}
7172
catch (InternalError e)
7273
{
73-
cx.cx.Extractor.Message(new Message
74-
{
75-
exception = e,
76-
message = "Error processing type definition",
77-
severity = Semmle.Util.Logging.Severity.Error
78-
});
74+
cx.cx.ExtractionError("Error processing type definition", e.Message, GeneratedLocation.Create(cx.cx), e.StackTrace);
7975
}
8076

8177
// Limitation of C#: Cannot yield return inside a try-catch.
@@ -92,12 +88,7 @@ public override IEnumerable<IExtractionProduct> Contents
9288
}
9389
catch (InternalError e)
9490
{
95-
cx.cx.Extractor.Message(new Message
96-
{
97-
exception = e,
98-
message = "Error processing bytecode",
99-
severity = Semmle.Util.Logging.Severity.Error
100-
});
91+
cx.cx.ExtractionError("Error processing bytecode", e.Message, GeneratedLocation.Create(cx.cx), e.StackTrace);
10192
}
10293

10394
if (product != null)

csharp/extractor/Semmle.Extraction.CIL/Entities/Instruction.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public override IEnumerable<IExtractionProduct> Contents
409409
}
410410
else
411411
{
412-
throw new InternalError("Unable to create payload type {0} for opcode {1}", PayloadType, OpCode);
412+
throw new InternalError($"Unable to create payload type {PayloadType} for opcode {OpCode}");
413413
}
414414
break;
415415
case Payload.Arg8:
@@ -430,7 +430,7 @@ public override IEnumerable<IExtractionProduct> Contents
430430
// Some of these are handled by JumpContents().
431431
break;
432432
default:
433-
throw new InternalError("Unhandled payload type {0}", PayloadType);
433+
throw new InternalError($"Unhandled payload type {PayloadType}");
434434
}
435435
}
436436
}
@@ -479,7 +479,7 @@ public IEnumerable<IExtractionProduct> JumpContents(Dictionary<int, IInstruction
479479
// TODO: Find a solution to this.
480480

481481
// For now, just log the error
482-
cx.cx.Extractor.Message(new Message { message = "A CIL instruction jumps outside the current method", severity = Util.Logging.Severity.Warning });
482+
cx.cx.ExtractionError("A CIL instruction jumps outside the current method", "", Extraction.Entities.GeneratedLocation.Create(cx.cx), "", Util.Logging.Severity.Warning);
483483
}
484484
}
485485
}

csharp/extractor/Semmle.Extraction.CIL/Entities/Method.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ public override IEnumerable<IExtractionProduct> Contents
497497
constructedTypeSignature = md.DecodeSignature(cx.TypeSignatureDecoder, this);
498498
break;
499499
default:
500-
throw new InternalError("Unexpected constructed method handle kind {0}", ms.Method.Kind);
500+
throw new InternalError($"Unexpected constructed method handle kind {ms.Method.Kind}");
501501
}
502502

503503
PopulateParameters(constructedTypeSignature.ParameterTypes);

csharp/extractor/Semmle.Extraction.CIL/Id.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public static StringId Id(this PrimitiveTypeCode typeCode)
197197
case PrimitiveTypeCode.UIntPtr: return uintptrId;
198198
case PrimitiveTypeCode.Void: return voidId;
199199
case PrimitiveTypeCode.TypedReference: return typedReferenceId;
200-
default: throw new InternalError("Unhandled type code {0}", typeCode);
200+
default: throw new InternalError($"Unhandled type code {typeCode}");
201201
}
202202
}
203203
}

csharp/extractor/Semmle.Extraction.CSharp/Analyser.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ void SetReferencePaths()
9999
}
100100
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
101101
{
102-
extractor.Message(new Message
103-
{
104-
exception = ex,
105-
message = string.Format("Exception reading reference file {0}: {1}",
106-
reference.FilePath, ex)
107-
});
102+
extractor.Message(new Message("Exception reading reference file", reference.FilePath, null, ex.StackTrace));
108103
}
109104
}
110105
}
@@ -388,7 +383,7 @@ void DoExtractTree(SyntaxTree tree)
388383
}
389384
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
390385
{
391-
extractor.Message(new Message { exception = ex, message = string.Format("Unhandled exception processing {0}: {1}", tree.FilePath, ex), severity = Severity.Error });
386+
extractor.Message(new Message("Unhandled exception processing syntax tree", tree.FilePath, null, ex.StackTrace));
392387
}
393388
}
394389

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ So we split it into separate lines
105105
break;
106106
// Strangely, these are reported as SingleLineCommentTrivia.
107107
case SyntaxKind.DocumentationCommentExteriorTrivia:
108-
cx.ModelError("Unhandled comment type {0} for {1}", trivia.Kind(), trivia);
108+
cx.ModelError($"Unhandled comment type {trivia.Kind()} for {trivia}");
109109
break;
110110
}
111111
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static ExprKind AccessKind(Context cx, ISymbol symbol)
3434
return ExprKind.PARAMETER_ACCESS;
3535

3636
default:
37-
cx.ModelError(symbol, "Unhandled access kind '{0}'", symbol.Kind);
37+
cx.ModelError(symbol, $"Unhandled access kind '{symbol.Kind}'");
3838
return ExprKind.UNKNOWN;
3939
}
4040
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static ExprKind GetBinaryTokenKind(Context cx, SyntaxKind kind)
5353
case SyntaxKind.QuestionQuestionToken: return ExprKind.NULL_COALESCING;
5454
// !! And the rest
5555
default:
56-
cx.ModelError("Unhandled operator type {0}", kind);
56+
cx.ModelError($"Unhandled operator type {kind}");
5757
return ExprKind.UNKNOWN;
5858
}
5959
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ internal static Expression Create(ExpressionNodeInfo info)
233233
return IsPattern.Create(info);
234234

235235
default:
236-
info.Context.ModelError(info.Node, "Unhandled expression '{0}' of kind '{1}'", info.Node, info.Node.Kind());
236+
info.Context.ModelError(info.Node, $"Unhandled expression '{info.Node}' of kind '{info.Node.Kind()}'");
237237
return new Unknown(info);
238238
}
239239
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override void Populate()
2828
new Expression(new ExpressionInfo(cx, Type, cx.Create(c.GetLocation()), ExprKind.STRING_LITERAL, this, child++, false, interpolatedText.TextToken.Text));
2929
break;
3030
default:
31-
throw new InternalError(c, "Unhandled interpolation kind {0}", c.Kind());
31+
throw new InternalError(c, $"Unhandled interpolation kind {c.Kind()}");
3232
}
3333
}
3434
}

0 commit comments

Comments
 (0)