Skip to content

Commit

Permalink
ChatReader: add try catch to prevent crash if parsing fails
Browse files Browse the repository at this point in the history
  • Loading branch information
lionaneesh authored Dec 16, 2024
1 parent 07d2622 commit f62006a
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Core/Chat/ChatReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,18 @@ public void Update(IAddonDataProvider reader)

string text = sb.ToString().ToLowerInvariant();
sb.Clear();

int firstSpaceIdx = text.AsSpan().IndexOf(' ');
string author = text.AsSpan(0, firstSpaceIdx).ToString();
string msg = text.AsSpan(firstSpaceIdx + 1).ToString();

ChatMessageEntry entry = new(DateTime.Now, type, author, msg);
Messages.Add(entry);
logger.LogInformation(entry.ToString());
try
{
int firstSpaceIdx = text.AsSpan().IndexOf(' ');
string author = text.AsSpan(0, firstSpaceIdx).ToString();
string msg = text.AsSpan(firstSpaceIdx + 1).ToString();

ChatMessageEntry entry = new(DateTime.Now, type, author, msg);
Messages.Add(entry);
logger.LogInformation(entry.ToString());
} catch (Exception e)
{
logger.LogError("ChatEntryError: " + e.ToString());
}
}
}

0 comments on commit f62006a

Please sign in to comment.