Skip to content

Commit

Permalink
Throw TypeLoadException when an actor type or dependency cannot be …
Browse files Browse the repository at this point in the history
…found in a remote actor deploy scenario

Actively handle cases where a null actor type is passed to a Props constructor
  • Loading branch information
rdavisau committed Sep 8, 2015
1 parent 9b917ec commit ffed3eb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/core/Akka.Remote/Serialization/DaemonMsgCreateSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,23 @@ private DeployData GetDeployData(Deploy deploy)
public override object FromBinary(byte[] bytes, Type type)
{
var proto = DaemonMsgCreateData.ParseFrom(bytes);
var clazz = Type.GetType(proto.Props.Clazz);
Type clazz;

try
{
clazz = Type.GetType(proto.Props.Clazz, true);
}
catch (TypeLoadException ex)
{
var msg = string.Format(
"Could not find type '{0}' on the remote system. " +
"Ensure that the remote system has an assembly that contains the type {0} in its assembly search path",
proto.Props.Clazz);


throw new TypeLoadException(msg, ex);
}

var args = GetArgs(proto);
var props = new Props(GetDeploy(proto.Props.Deploy), clazz, args);
return new DaemonMsgCreate(
Expand Down
20 changes: 20 additions & 0 deletions src/core/Akka.Tests/Actor/PropsSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Akka.Actor;
using Akka.TestKit;
using System;
using System.Linq;
using Xunit;

namespace Akka.Tests.Actor
Expand Down Expand Up @@ -56,6 +57,25 @@ public void Props_created_with_strategy_must_have_it_set()
Assert.Equal(strategy, props.SupervisorStrategy);
}

[Fact]
public void Props_created_with_null_type_must_throw()
{
Type missingType = null;
object[] args = new object[0];
var argsEnumerable = Enumerable.Empty<object>();
var defaultStrategy = SupervisorStrategy.DefaultStrategy;
var defaultDeploy = Deploy.Local;

Props p = null;

Assert.Throws<ArgumentNullException>("type", () => p = new Props(missingType, args));
Assert.Throws<ArgumentNullException>("type", () => p = new Props(missingType));
Assert.Throws<ArgumentNullException>("type", () => p = new Props(missingType, defaultStrategy, argsEnumerable));
Assert.Throws<ArgumentNullException>("type", () => p = new Props(missingType, defaultStrategy, args));
Assert.Throws<ArgumentNullException>("type", () => p = new Props(defaultDeploy, missingType, argsEnumerable));
Assert.Throws<ArgumentNullException>("type", () => p = Props.Create(missingType, args));
}

private class TestProducer : IIndirectActorProducer
{
TestLatch latchActor;
Expand Down
17 changes: 17 additions & 0 deletions src/core/Akka/Actor/Props.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace Akka.Actor
/// </summary>
public class Props : IEquatable<Props> , ISurrogated
{
private const string NullActorTypeExceptionText = "Props must be instantiated with an actor type.";

public class PropsSurrogate : ISurrogate
{
public Type Type { get; set; }
Expand Down Expand Up @@ -183,6 +185,8 @@ protected Props(Props copy)
public Props(Type type, object[] args)
: this(defaultDeploy, type, args)
{
if (type == null)
throw new ArgumentNullException("type", NullActorTypeExceptionText);
}

/// <summary>
Expand All @@ -192,6 +196,8 @@ public Props(Type type, object[] args)
public Props(Type type)
: this(defaultDeploy, type, noArgs)
{
if (type == null)
throw new ArgumentNullException("type", NullActorTypeExceptionText);
}

/// <summary>
Expand All @@ -203,6 +209,9 @@ public Props(Type type)
public Props(Type type, SupervisorStrategy supervisorStrategy, IEnumerable<object> args)
: this(defaultDeploy, type, args.ToArray())
{
if (type == null)
throw new ArgumentNullException("type", NullActorTypeExceptionText);

SupervisorStrategy = supervisorStrategy;
}

Expand All @@ -215,6 +224,9 @@ public Props(Type type, SupervisorStrategy supervisorStrategy, IEnumerable<objec
public Props(Type type, SupervisorStrategy supervisorStrategy, params object[] args)
: this(defaultDeploy, type, args)
{
if (type == null)
throw new ArgumentNullException("type", NullActorTypeExceptionText);

SupervisorStrategy = supervisorStrategy;
}

Expand All @@ -227,6 +239,8 @@ public Props(Type type, SupervisorStrategy supervisorStrategy, params object[] a
public Props(Deploy deploy, Type type, IEnumerable<object> args)
: this(deploy, type, args.ToArray())
{
if (type == null)
throw new ArgumentNullException("type", NullActorTypeExceptionText);
}

/// <summary>
Expand Down Expand Up @@ -394,6 +408,9 @@ public static Props CreateBy<TProducer>(params object[] args) where TProducer :
/// <returns>Props.</returns>
public static Props Create(Type type, params object[] args)
{
if (type == null)
throw new ArgumentNullException("type", NullActorTypeExceptionText);

return new Props(type, args);
}

Expand Down

0 comments on commit ffed3eb

Please sign in to comment.