Surfacing non-fatal parse errors in Test Harness output

This commit is contained in:
Josh Slocum 2021-05-19 19:57:51 +00:00
parent 676f946c47
commit d067ca507b
3 changed files with 31 additions and 16 deletions

View File

@ -717,7 +717,7 @@ namespace SummarizeTest
delegate IEnumerable<Magnesium.Event> parseDelegate(System.IO.Stream stream, string file,
bool keepOriginalElement = false, double startTime = -1, double endTime = Double.MaxValue,
double samplingFactor = 1.0);
double samplingFactor = 1.0, Action<string> nonFatalErrorMessage = null);
static int Summarize(string[] traceFiles, string summaryFileName,
string errorFileName, bool? killed, List<string> outputErrors, int? exitCode, long? peakMemory,
@ -750,12 +750,14 @@ namespace SummarizeTest
{
try
{
// Use Action to set this because IEnumerables with yield can't have an out variable
string nonFatalParseError = null;
parseDelegate parse;
if (traceFileName.EndsWith(".json"))
parse = Magnesium.JsonParser.Parse;
else
parse = Magnesium.XmlParser.Parse;
foreach (var ev in parse(traceFile, traceFileName))
foreach (var ev in parse(traceFile, traceFileName, nonFatalErrorMessage: (x) => { nonFatalParseError = x; }))
{
Magnesium.Severity newSeverity;
if (severityMap.TryGetValue(new KeyValuePair<string, Magnesium.Severity>(ev.Type, ev.Severity), out newSeverity))
@ -876,6 +878,11 @@ namespace SummarizeTest
if (ev.Type == "StderrSeverity")
stderrSeverity = int.Parse(ev.Details.NewSeverity);
}
if (nonFatalParseError != null) {
xout.Add(new XElement("NonFatalParseError",
new XAttribute("Severity", (int)Magnesium.Severity.SevWarnAlways),
new XAttribute("ErrorMessage", nonFatalParseError)));
}
}
catch (Exception e)

View File

@ -1,4 +1,4 @@
/*
/*
* JsonParser.cs
*
* This source file is part of the FoundationDB open source project
@ -34,9 +34,10 @@ namespace Magnesium
{
static Random r = new Random();
// dummy parameter nonFatalParseError to match xml
public static IEnumerable<Event> Parse(System.IO.Stream stream, string file,
bool keepOriginalElement = false, double startTime = -1, double endTime = Double.MaxValue,
double samplingFactor = 1.0)
double samplingFactor = 1.0, Action<string> nonFatalErrorMessage = null)
{
using (var reader = new System.IO.StreamReader(stream))
{

View File

@ -33,14 +33,29 @@ namespace Magnesium
public static IEnumerable<Event> Parse(System.IO.Stream stream, string file,
bool keepOriginalElement = false, double startTime = -1, double endTime = Double.MaxValue,
double samplingFactor = 1.0)
double samplingFactor = 1.0, Action<string> nonFatalErrorMessage = null)
{
using (var reader = XmlReader.Create(stream))
{
reader.ReadToDescendant("Trace");
reader.Read();
foreach (var xev in StreamElements(reader))
// foreach (var xev in StreamElements(reader))
// need to be able to catch and save non-fatal exceptions in StreamElements, so use explicit iterator instead of foreach
var iter = StreamElements(reader).GetEnumerator();
while (true)
{
try {
if (!iter.MoveNext()) {
break;
}
} catch (Exception e) {
if (nonFatalErrorMessage != null) {
nonFatalErrorMessage(e.Message);
}
break;
}
var xev = iter.Current;
Event ev = null;
try
{
@ -165,28 +180,20 @@ namespace Magnesium
}
}
// throws exceptions if xml is invalid
private static IEnumerable<XElement> StreamElements(this XmlReader reader)
{
while (!reader.EOF)
{
if (reader.NodeType == XmlNodeType.Element)
{
XElement node = null;
try
{
node = XElement.ReadFrom(reader) as XElement;
}
catch (Exception) { break; }
XElement node = XElement.ReadFrom(reader) as XElement;
if (node != null)
yield return node;
}
else
{
try
{
reader.Read();
}
catch (Exception) { break; }
}
}
}