From f62006a63575ad53b4f0b753d381d33e1af65c51 Mon Sep 17 00:00:00 2001 From: Aneesh Dogra Date: Mon, 16 Dec 2024 19:14:27 +0100 Subject: [PATCH] ChatReader: add try catch to prevent crash if parsing fails --- Core/Chat/ChatReader.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Core/Chat/ChatReader.cs b/Core/Chat/ChatReader.cs index c98c455c..f28eb567 100644 --- a/Core/Chat/ChatReader.cs +++ b/Core/Chat/ChatReader.cs @@ -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()); + } } }