diff --git a/Lagrange.Core/Internal/Context/SocketContext.cs b/Lagrange.Core/Internal/Context/SocketContext.cs index c0062e3..dace0ae 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 ce69b70..70a7d4e 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