Skip to content

Commit

Permalink
fix: improving error for failed deserialize
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Jun 17, 2021
1 parent 7c90eaa commit 2e1601b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
25 changes: 25 additions & 0 deletions Assets/Mirage/Runtime/DeserializeFailedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Runtime.Serialization;

namespace Mirage
{

[Serializable]
public class DeserializeFailedException : Exception
{
public DeserializeFailedException()
{
}

public DeserializeFailedException(string message) : base(message)
{
}

public DeserializeFailedException(string message, Exception innerException) : base(message, innerException)
{
}
protected DeserializeFailedException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
25 changes: 0 additions & 25 deletions Assets/Mirage/Runtime/InvalidMessageException.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ void OnDeserialize(NetworkBehaviour comp, NetworkReader reader, bool initialStat
byte barrierData = reader.ReadByte();
if (barrierData != Barrier)
{
throw new InvalidMessageException($"OnDeserialize failed for: object={name} component={comp.GetType()} sceneId={sceneId}. Possible Reasons:\n" +
throw new DeserializeFailedException($"Deserialize not aligned for object={name} netId={NetId} component={comp.GetType()} sceneId={sceneId}. Possible Reasons:\n" +
$" * Do {comp.GetType()}'s OnSerialize and OnDeserialize calls write the same amount of data? \n" +
$" * Are the server and client the exact same project?\n" +
$" * Maybe this OnDeserialize call was meant for another GameObject? The sceneIds can easily get out of sync if the Hierarchy was modified only in the client OR the server. Try rebuilding both.\n\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
namespace Mirage
{
[TestFixture]
public class InvalidMessageExceptionTest
public class DeserializeFailedExceptionTest
{
[Test]
public void InvalidMessageTest()
{
Assert.Throws<InvalidMessageException>(() =>
Assert.Throws<DeserializeFailedException>(() =>
{
throw new InvalidMessageException();
throw new DeserializeFailedException();
});
}

[Test]
public void InvalidMessageWithTextTest()
{
InvalidMessageException ex = Assert.Throws<InvalidMessageException>(() =>
DeserializeFailedException ex = Assert.Throws<DeserializeFailedException>(() =>
{
throw new InvalidMessageException("Test Message");
throw new DeserializeFailedException("Test Message");
});

Assert.That(ex.Message, Is.EqualTo("Test Message"));
Expand All @@ -28,9 +28,9 @@ public void InvalidMessageWithTextTest()
[Test]
public void InvalidMessageWithTextAndInnerTest()
{
InvalidMessageException ex = Assert.Throws<InvalidMessageException>(() =>
DeserializeFailedException ex = Assert.Throws<DeserializeFailedException>(() =>
{
throw new InvalidMessageException("Test Message Too", new System.Exception());
throw new DeserializeFailedException("Test Message Too", new System.Exception());
});

Assert.That(ex.Message, Is.EqualTo("Test Message Too"));
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Editor/NetworkIdentityCallbackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public void OnDeserializeSafelyShouldDetectAndHandleDeSerializationMismatch()

// deserialize all
var reader = new NetworkReader(ownerWriter.ToArray());
Assert.Throws<InvalidMessageException>(() =>
Assert.Throws<DeserializeFailedException>(() =>
{
identity.OnDeserializeAll(reader, true);
});
Expand Down

0 comments on commit 2e1601b

Please sign in to comment.