Skip to content

Commit

Permalink
Merge pull request #264 from AoshiW/parsing-error
Browse files Browse the repository at this point in the history
catch parsing error
  • Loading branch information
Syzuna authored Mar 25, 2024
2 parents 0fa8038 + aadb9a5 commit f54d60b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions TwitchLib.Client/Extensions/LogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ internal static partial class LogExtensions
[LoggerMessage(LogLevel.Warning, "Unaccounted for: {ircString} (please create a TwitchLib GitHub issue :P)")]
public static partial void LogUnaccountedFor(this ILogger<TwitchClient> logger, string ircString);

[LoggerMessage(LogLevel.Error, "Unexpected error during message parsing, message: {message}")]
public static partial void LogParsingError(this ILogger<TwitchClient> logger, string message, Exception ex);

[LoggerMessage(LogLevel.Debug, "Writing: {message}")]
public static partial void LogWriting(this ILogger<TwitchClient> logger, string message);

Expand Down
13 changes: 12 additions & 1 deletion TwitchLib.Client/TwitchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,18 @@ private async Task _client_OnMessage(object? sender, OnMessageEventArgs e)
_logger?.LogReceived(line);

await OnSendReceiveData.TryInvoke(this, new(SendReceiveDirection.Received, line));
await HandleIrcMessageAsync(IrcParser.ParseMessage(line));
IrcMessage ircMessage;
try
{
ircMessage = IrcParser.ParseMessage(line);
}
catch (Exception ex)
{
_logger?.LogParsingError(line, ex);
OnError?.Invoke(this, new(ex));
continue;
}
await HandleIrcMessageAsync(ircMessage);
}
}

Expand Down

0 comments on commit f54d60b

Please sign in to comment.