From c5f46c8e8b582d65c8412b984eca81bd50c08628 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 25 Aug 2025 04:26:08 +0000 Subject: [PATCH 1/2] Initial plan From c6841cd41727c77b856af438a5d3eb0a51dcabfe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 25 Aug 2025 04:34:54 +0000 Subject: [PATCH 2/2] Add exception handling to BaseService Parse method and SocketContext OnSocketError Co-authored-by: DarkRRb <177549718+DarkRRb@users.noreply.github.com> --- Lagrange.Core/Internal/Context/SocketContext.cs | 2 +- Lagrange.Core/Internal/Services/BaseService.cs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Lagrange.Core/Internal/Context/SocketContext.cs b/Lagrange.Core/Internal/Context/SocketContext.cs index c0062e32..dace0aef 100644 --- a/Lagrange.Core/Internal/Context/SocketContext.cs +++ b/Lagrange.Core/Internal/Context/SocketContext.cs @@ -39,7 +39,7 @@ public void OnDisconnect() public void OnSocketError(Exception e, ReadOnlyMemory data) { - + _context.LogError(Tag, "Socket error occurred during packet processing: {0}", e, e.Message); } public async Task Connect() diff --git a/Lagrange.Core/Internal/Services/BaseService.cs b/Lagrange.Core/Internal/Services/BaseService.cs index ce69b703..70a7d4ea 100644 --- a/Lagrange.Core/Internal/Services/BaseService.cs +++ b/Lagrange.Core/Internal/Services/BaseService.cs @@ -4,11 +4,24 @@ namespace Lagrange.Core.Internal.Services; internal abstract class BaseService : IService where TReq : ProtocolEvent where TResp : ProtocolEvent { + private const string Tag = nameof(BaseService); + protected virtual ValueTask Parse(ReadOnlyMemory input, BotContext context) => ValueTask.FromResult(null!); protected virtual ValueTask> Build(TReq input, BotContext context) => ValueTask.FromResult(ReadOnlyMemory.Empty); - async ValueTask IService.Parse(ReadOnlyMemory input, BotContext context) => await Parse(input, context); + async ValueTask IService.Parse(ReadOnlyMemory input, BotContext context) + { + try + { + return await Parse(input, context); + } + catch (Exception e) + { + context.LogError(Tag, "Parse method failed for service {0}", e, GetType().Name); + throw; + } + } ValueTask> IService.Build(ProtocolEvent input, BotContext context) => Build((TReq)input, context); } \ No newline at end of file