From be532b310f3d4b0e3cd96cc2ff1ab571f8b01b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20L=2E=20Kiss?= <50739844+jozseflkiss@users.noreply.github.com> Date: Tue, 9 Jan 2024 10:08:36 +0100 Subject: [PATCH] fix(Archicad): CNX-8392 Handle CA1031 warnings in ArchiCAD projects (#3122) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CNX-8392 Handle CA1031 warnings in ArchiCAD projects * add exceptions to log * simplify --------- Co-authored-by: JoĢzsef L. Kiss <> --- .../Communication/AsyncCommandProcessor.cs | 8 ++++++- .../ConnectorArchicad/ConnectorBinding.cs | 22 ++++++------------- .../ElementConverterManagerReceive.cs | 10 ++++----- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/ConnectorArchicad/ConnectorArchicad/Communication/AsyncCommandProcessor.cs b/ConnectorArchicad/ConnectorArchicad/Communication/AsyncCommandProcessor.cs index c0a20ce18f..4061077508 100644 --- a/ConnectorArchicad/ConnectorArchicad/Communication/AsyncCommandProcessor.cs +++ b/ConnectorArchicad/ConnectorArchicad/Communication/AsyncCommandProcessor.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Speckle.Core.Logging; namespace Archicad.Communication; @@ -27,10 +28,15 @@ internal class AsyncCommandProcessor { return Task.Run(command.Execute, token); } - catch (Exception e) + catch (ArgumentNullException) { return null; } + catch (Exception ex) when (ex is TaskCanceledException or ObjectDisposedException) + { + SpeckleLog.Logger.Error(ex, "Could not communicate with Archicad."); + return null; + } } #endregion diff --git a/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs b/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs index ea86789727..97f32adba6 100644 --- a/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs +++ b/ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs @@ -174,22 +174,14 @@ public override async Task ReceiveStream(StreamState state, Progres } } } - catch (Exception ex) + catch (SpeckleException) { - // log - if (ex is not OperationCanceledException) - { - SpeckleLog.Logger.Error("Conversion to native failed."); - } - - // throw - switch (ex) - { - case OperationCanceledException: - throw new OperationCanceledException(ex.Message); - default: - throw new SpeckleException(ex.Message, ex); - } + SpeckleLog.Logger.Error("Conversion to native failed."); + throw; + } + catch (OperationCanceledException) + { + throw; } return state; diff --git a/ConnectorArchicad/ConnectorArchicad/Converters/ElementConverterManagerReceive.cs b/ConnectorArchicad/ConnectorArchicad/Converters/ElementConverterManagerReceive.cs index 5ab5e5eb7a..d70823dfe0 100644 --- a/ConnectorArchicad/ConnectorArchicad/Converters/ElementConverterManagerReceive.cs +++ b/ConnectorArchicad/ConnectorArchicad/Converters/ElementConverterManagerReceive.cs @@ -26,14 +26,14 @@ CancellationToken token var elementConverter = GetConverterForElement(elementType, conversionOptions, true); return await elementConverter.ConvertToArchicad(elements, token); } - catch (OperationCanceledException) + catch (Exception ex) when (ex is SpeckleException or ArgumentNullException or ObjectDisposedException) { - throw; + SpeckleLog.Logger.Warning(ex, "Failed to convert element type {elementType}", elementType.ToString()); + return null; } - catch (Exception) + catch (OperationCanceledException) { - SpeckleLog.Logger.Warning("Failed to convert element type {elementType}", elementType.ToString()); - return null; + throw; } }