Skip to content

Commit

Permalink
Dynamo: Handle deserialisation errors on Receive (#1745)
Browse files Browse the repository at this point in the history
* fix(dyn): Hide System.EventArgs from showing

* fix(dyn): Handle deserialisation errors better
  • Loading branch information
AlanRynne authored Oct 19, 2022
1 parent 8b7aa6d commit 0a57040
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ConnectorDynamo/ConnectorDynamo/ReceiveNode/Receive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ void ErrorAction(string transportName, Exception e)
{
if (!_cancellationToken.IsCancellationRequested)
{
//_cancellationToken.Cancel();
_cancellationToken.Cancel();
var msg = e.ToFormattedString();
Message = msg.Contains("401") || msg.Contains("don't have access") ? "Not authorized" : "Error";
Warning(msg);
_errors.Add(e);
//throw;
throw;
}
}
finally
Expand Down
12 changes: 1 addition & 11 deletions ConnectorDynamo/ConnectorDynamoFunctions/BatchConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private ISpeckleKit _kit
get;
set;
}

public EventHandler<OnErrorEventArgs> OnError;

public BatchConverter()
Expand Down Expand Up @@ -331,16 +332,5 @@ public static bool IsDictionary(object @object)
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>);
}
}

[IsVisibleInDynamoLibrary(false)]
public class OnErrorEventArgs : EventArgs
{
public Exception Error;

public OnErrorEventArgs(Exception error)
{
Error = error;
}
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -72,6 +72,7 @@
<Compile Include="InMemoryCache.cs" />
<Compile Include="Account.cs" />
<Compile Include="Functions.cs" />
<Compile Include="OnErrorEventArgs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Stream.cs" />
<Compile Include="BatchConverter.cs" />
Expand Down
7 changes: 6 additions & 1 deletion ConnectorDynamo/ConnectorDynamoFunctions/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Threading;
using Autodesk.DesignScript.Runtime;
using Sentry;
using Speckle.Core.Api;
using Speckle.Core.Credentials;
using Speckle.Core.Kits;
Expand Down Expand Up @@ -159,11 +160,15 @@ public static Dictionary<string, object> Receive(StreamWrapper stream, Cancellat
cancellationToken,
remoteTransport: transport,
onProgressAction: onProgressAction,
onErrorAction: onErrorAction,
onErrorAction: ((s, exception) => throw exception),
onTotalChildrenCountKnown: onTotalChildrenCountKnown,
disposeTransports: true
).Result;

if (@base == null)
{
throw new SpeckleException("Receive operation returned nothing", false);
}
try
{
client.CommitReceived(new CommitReceivedInput
Expand Down
16 changes: 16 additions & 0 deletions ConnectorDynamo/ConnectorDynamoFunctions/OnErrorEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Autodesk.DesignScript.Runtime;

namespace Speckle.ConnectorDynamo
{
[IsVisibleInDynamoLibrary(false)]
public class OnErrorEventArgs
{
public Exception Error;

public OnErrorEventArgs(Exception error)
{
Error = error;
}
}
}

0 comments on commit 0a57040

Please sign in to comment.