Skip to content

Commit

Permalink
fix(Archicad): CNX-8392 Handle CA1031 warnings in ArchiCAD projects (#…
Browse files Browse the repository at this point in the history
…3122)

* CNX-8392 Handle CA1031 warnings in ArchiCAD projects

* add exceptions to log

* simplify

---------

Co-authored-by: József L. Kiss <>
  • Loading branch information
jozseflkiss authored Jan 9, 2024
1 parent 5bf6a8d commit be532b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Speckle.Core.Logging;

namespace Archicad.Communication;

Expand All @@ -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
Expand Down
22 changes: 7 additions & 15 deletions ConnectorArchicad/ConnectorArchicad/ConnectorBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,14 @@ public override async Task<StreamState> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit be532b3

Please sign in to comment.