diff --git a/src/Speckle.Sdk/Serialisation/V2/Receive/DeserializeProcess.cs b/src/Speckle.Sdk/Serialisation/V2/Receive/DeserializeProcess.cs index 6a2714e0..b0e65a7c 100644 --- a/src/Speckle.Sdk/Serialisation/V2/Receive/DeserializeProcess.cs +++ b/src/Speckle.Sdk/Serialisation/V2/Receive/DeserializeProcess.cs @@ -41,7 +41,13 @@ public sealed class DeserializeProcess( : #pragma warning disable CA2000 this( - new ObjectLoader(sqLiteJsonCacheManager, serverObjectManager, progress, cancellationToken), + new ObjectLoader( + sqLiteJsonCacheManager, + serverObjectManager, + progress, + loggerFactory.CreateLogger(), + cancellationToken + ), progress, baseDeserializer, loggerFactory, diff --git a/src/Speckle.Sdk/Serialisation/V2/Receive/ObjectLoader.cs b/src/Speckle.Sdk/Serialisation/V2/Receive/ObjectLoader.cs index 2a692f5f..3ba7c701 100644 --- a/src/Speckle.Sdk/Serialisation/V2/Receive/ObjectLoader.cs +++ b/src/Speckle.Sdk/Serialisation/V2/Receive/ObjectLoader.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using Speckle.InterfaceGenerator; using Speckle.Sdk.Common; using Speckle.Sdk.Dependencies; @@ -16,6 +17,7 @@ public sealed class ObjectLoader( ISqLiteJsonCacheManager sqLiteJsonCacheManager, IServerObjectManager serverObjectManager, IProgress? progress, + ILogger logger, CancellationToken cancellationToken #pragma warning disable CS9107 // Parameter is captured into the state of the enclosing type and its value is also passed to the base constructor. The value might be captured by the base class as well. ) : ChannelLoader(cancellationToken), IObjectLoader @@ -129,12 +131,32 @@ public sealed class ObjectLoader( [AutoInterfaceIgnore] protected override void SaveToCacheInternal(List batch) { - if (!_options.SkipCache) + try { - cancellationToken.ThrowIfCancellationRequested(); - sqLiteJsonCacheManager.SaveObjects(batch.Select(x => (x.Id.Value, x.Json.Value))); - Interlocked.Exchange(ref _cached, _cached + batch.Count); - progress?.Report(new(ProgressEvent.CachedToLocal, _cached, _allChildrenCount)); + if (!_options.SkipCache) + { + cancellationToken.ThrowIfCancellationRequested(); + sqLiteJsonCacheManager.SaveObjects(batch.Select(x => (x.Id.Value, x.Json.Value))); + Interlocked.Exchange(ref _cached, _cached + batch.Count); + progress?.Report(new(ProgressEvent.CachedToLocal, _cached, _allChildrenCount)); + } + } + catch (OperationCanceledException) + { + throw; + } +#pragma warning disable CA1031 + catch (Exception) +#pragma warning restore CA1031 + { + logger.LogError( + "Error while saving to cache, some stats of the payload: {Count} objects, {Serialized} serialized, {Cached} cached, {BatchByteSize} batch bytes", + batch.Count, + _allChildrenCount, + _cached, + batch.Sum(x => x.ByteSize) + ); + throw; } } diff --git a/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSaver.cs b/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSaver.cs index f325e1f4..3a73a221 100644 --- a/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSaver.cs +++ b/src/Speckle.Sdk/Serialisation/V2/Send/ObjectSaver.cs @@ -74,6 +74,13 @@ public sealed class ObjectSaver( #pragma warning restore CA1031 { RecordException(e); + logger.LogError( + "Error while sending objects to server, some stats of the payload: {Count} objects, {Serialized} serialized, {Cached} cached, {BatchByteSize} batch bytes", + batch.Items.Count, + _objectsSerialized, + _cached, + batch.BatchByteSize + ); } } @@ -107,6 +114,13 @@ public sealed class ObjectSaver( #pragma warning restore CA1031 { RecordException(e); + logger.LogError( + "Error while saving to cache, some stats of the payload: {Count} objects, {Serialized} serialized, {Cached} cached, {BatchByteSize} batch bytes", + batch.Count, + _objectsSerialized, + _cached, + batch.Sum(x => x.ByteSize) + ); } } diff --git a/tests/Speckle.Sdk.Serialization.Tests/ExceptionTests.cs b/tests/Speckle.Sdk.Serialization.Tests/ExceptionTests.cs index 3eeed762..ca58b036 100644 --- a/tests/Speckle.Sdk.Serialization.Tests/ExceptionTests.cs +++ b/tests/Speckle.Sdk.Serialization.Tests/ExceptionTests.cs @@ -112,6 +112,7 @@ public class ExceptionTests new DummySqLiteReceiveManager(new Dictionary()), new ExceptionServerObjectManager(), null, + new NullLogger(), default ); await using var process = new DeserializeProcess( diff --git a/tests/Speckle.Sdk.Serialization.Tests/SerializationTests.cs b/tests/Speckle.Sdk.Serialization.Tests/SerializationTests.cs index 7a2f2c62..318b7125 100644 --- a/tests/Speckle.Sdk.Serialization.Tests/SerializationTests.cs +++ b/tests/Speckle.Sdk.Serialization.Tests/SerializationTests.cs @@ -196,6 +196,7 @@ public class SerializationTests new DummySqLiteReceiveManager(closures), new DummyReceiveServerObjectManager(closures), null, + new NullLogger(), default ) )