diff --git a/CryptoExchange.Net.Protobuf/Converters/Protobuf/ProtobufMessageAccessor.cs b/CryptoExchange.Net.Protobuf/Converters/Protobuf/ProtobufMessageAccessor.cs index d497428..8414246 100644 --- a/CryptoExchange.Net.Protobuf/Converters/Protobuf/ProtobufMessageAccessor.cs +++ b/CryptoExchange.Net.Protobuf/Converters/Protobuf/ProtobufMessageAccessor.cs @@ -348,6 +348,7 @@ namespace CryptoExchange.Net.Converters.Protobuf { _stream?.Dispose(); _stream = null; + _intermediateType = default; } } @@ -464,7 +465,7 @@ namespace CryptoExchange.Net.Converters.Protobuf { // Not a json message IsValid = false; - return new CallResult(new DeserializeError("JsonError: " + ex.Message, ex)); + return new CallResult(new DeserializeError("ProtobufError: " + ex.Message, ex)); } } @@ -484,6 +485,7 @@ namespace CryptoExchange.Net.Converters.Protobuf public override void Clear() { _bytes = null; + _intermediateType = default; } } } \ No newline at end of file diff --git a/CryptoExchange.Net/Logging/Extensions/SocketConnectionLoggingExtension.cs b/CryptoExchange.Net/Logging/Extensions/SocketConnectionLoggingExtension.cs index dfd9f7c..029c85e 100644 --- a/CryptoExchange.Net/Logging/Extensions/SocketConnectionLoggingExtension.cs +++ b/CryptoExchange.Net/Logging/Extensions/SocketConnectionLoggingExtension.cs @@ -15,6 +15,7 @@ namespace CryptoExchange.Net.Logging.Extensions private static readonly Action _webSocketError; private static readonly Action _messageSentNotPending; private static readonly Action _receivedData; + private static readonly Action _failedToParse; private static readonly Action _failedToEvaluateMessage; private static readonly Action _errorProcessingMessage; private static readonly Action _processorMatched; @@ -189,6 +190,11 @@ namespace CryptoExchange.Net.Logging.Extensions LogLevel.Warning, new EventId(2029, "ReceivedMessageNotMatchedToAnyListener"), "[Sckt {SocketId}] received message not matched to any listener. ListenId: {ListenId}, current listeners: {ListenIds}"); + + _failedToParse = LoggerMessage.Define( + LogLevel.Warning, + new EventId(2030, "FailedToParse"), + "[Sckt {SocketId}] failed to parse data: {Error}"); } public static void ActivityPaused(this ILogger logger, int socketId, bool paused) @@ -230,6 +236,12 @@ namespace CryptoExchange.Net.Logging.Extensions { _receivedData(logger, socketId, originalData, null); } + + public static void FailedToParse(this ILogger logger, int socketId, string error) + { + _failedToParse(logger, socketId, error, null); + } + public static void FailedToEvaluateMessage(this ILogger logger, int socketId, string originalData) { _failedToEvaluateMessage(logger, socketId, originalData, null); diff --git a/CryptoExchange.Net/Sockets/SocketConnection.cs b/CryptoExchange.Net/Sockets/SocketConnection.cs index 3e2a92f..a1d9502 100644 --- a/CryptoExchange.Net/Sockets/SocketConnection.cs +++ b/CryptoExchange.Net/Sockets/SocketConnection.cs @@ -465,7 +465,7 @@ namespace CryptoExchange.Net.Sockets else accessor = _byteMessageAccessor ??= ApiClient.CreateAccessor(type); - accessor.Read(data); + var result = accessor.Read(data); try { bool outputOriginalData = ApiClient.ApiOptions.OutputOriginalData ?? ApiClient.ClientOptions.OutputOriginalData; @@ -475,6 +475,12 @@ namespace CryptoExchange.Net.Sockets _logger.ReceivedData(SocketId, originalData); } + if (!accessor.IsValid) + { + _logger.FailedToParse(SocketId, result.Error!.Message); + return; + } + // 3. Determine the identifying properties of this message var listenId = ApiClient.GetListenerIdentifier(accessor); if (listenId == null)