no longer completely fail on one wrong entry

U17 might have caused some journal bugs so don't fail immediately on one wrong entry, instead keep them in an Errors collection for later processing
This commit is contained in:
Florian Stinglmayr 2023-10-25 11:30:34 +02:00
parent acb60e0a08
commit d6842115c5
4 changed files with 30 additions and 5 deletions

View File

@ -64,7 +64,15 @@ public class Entry {
public static Entry? Parse(string journalline) { public static Entry? Parse(string journalline) {
using (JsonReader reader = new JsonTextReader(new StringReader(journalline))) { using (JsonReader reader = new JsonTextReader(new StringReader(journalline))) {
reader.DateParseHandling = DateParseHandling.None; reader.DateParseHandling = DateParseHandling.None;
var json = JObject.Load(reader); JObject? json = null;
try {
json = JObject.Load(reader);
} catch (Exception e) {
throw new InvalidJournalEntryException(
"invalid JSON journal entry: " + journalline,
e
);
}
if (json == null) { if (json == null) {
return null; return null;
} }

View File

@ -6,6 +6,7 @@
public class InvalidJournalEntryException : Exception { public class InvalidJournalEntryException : Exception {
public InvalidJournalEntryException() { } public InvalidJournalEntryException() { }
public InvalidJournalEntryException(string message) : base(message) { } public InvalidJournalEntryException(string message) : base(message) { }
public InvalidJournalEntryException(string message, Exception inner) : base(message, inner) { }
} }
/// <summary> /// <summary>

View File

@ -17,6 +17,11 @@ public class JournalFile : IComparable<JournalFile>
private static Regex update11regex = new Regex("Journal\\.([^\\.]+)\\.(\\d+).log"); private static Regex update11regex = new Regex("Journal\\.([^\\.]+)\\.(\\d+).log");
private static string iso8601 = "yyyyMMddTHHmmss"; private static string iso8601 = "yyyyMMddTHHmmss";
/// <summary>
/// A public list of errors encountered while parsing the journal files
/// </summary>
public List<Exception> Errors { get; private set; } = new List<Exception>();
public static bool VerifyFile(string path) { public static bool VerifyFile(string path) {
string filename = Path.GetFileName(path); string filename = Path.GetFileName(path);
@ -125,15 +130,20 @@ public class JournalFile : IComparable<JournalFile>
} }
entries.Clear(); entries.Clear();
Errors.Clear();
foreach (var line in lines) { foreach (var line in lines) {
// Skip empty lines // Skip empty lines
if (line.Trim().Length == 0) { if (line.Trim().Length == 0) {
continue; continue;
} }
try {
Entry? entry = Entry.Parse(line); Entry? entry = Entry.Parse(line);
if (entry != null) { if (entry != null) {
entries.Add(entry); entries.Add(entry);
} }
} catch (Exception ex) {
Errors.Add(ex);
}
} }
} }
} }

View File

@ -22,6 +22,12 @@ public class PlayerJournal {
ScanFiles(); ScanFiles();
} }
public List<Exception> AllErrors {
get {
return Files.SelectMany(x => x.Errors).ToList();
}
}
public List<JournalFile> Files { public List<JournalFile> Files {
get { return journalfiles; } get { return journalfiles; }
} }