Skip to content

Commit

Permalink
fix: InvalidDataException not found problem
Browse files Browse the repository at this point in the history
Revert "Use standard exception instead of our own"

This reverts commit 10d2a1e.
  • Loading branch information
paulpach committed Oct 21, 2020
1 parent 5b8fb7d commit 229f73d
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
25 changes: 25 additions & 0 deletions Assets/Mirror/Runtime/InvalidMessageException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Runtime.Serialization;

namespace Mirror
{

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

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

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Assets/Mirror/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using UnityEngine.Events;
#if UNITY_EDITOR
using UnityEditor;
using System.IO;
#if UNITY_2018_3_OR_NEWER
using UnityEditor.Experimental.SceneManagement;
#endif
Expand Down Expand Up @@ -955,7 +954,7 @@ void OnDeserializeSafely(NetworkBehaviour comp, NetworkReader reader, bool initi
byte barrierData = reader.ReadByte();
if (barrierData != Barrier)
{
throw new InvalidDataException("OnDeserialize failed for: object=" + name + " component=" + comp.GetType() + " sceneId=" + sceneId + ". Possible Reasons:\n * Do " + comp.GetType() + "'s OnSerialize and OnDeserialize calls write the same amount of data? \n * Was there an exception in " + comp.GetType() + "'s OnSerialize/OnDeserialize code?\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");
throw new InvalidMessageException("OnDeserialize failed for: object=" + name + " component=" + comp.GetType() + " sceneId=" + sceneId + ". Possible Reasons:\n * Do " + comp.GetType() + "'s OnSerialize and OnDeserialize calls write the same amount of data? \n * Was there an exception in " + comp.GetType() + "'s OnSerialize/OnDeserialize code?\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
40 changes: 40 additions & 0 deletions Assets/Tests/Editor/InvalidMessageExceptionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using NUnit.Framework;

namespace Mirror.Tests
{
[TestFixture]
public class InvalidMessageExceptionTest
{
[Test]
public void InvalidMessageTest()
{
Assert.Throws<InvalidMessageException>(() =>
{
throw new InvalidMessageException();
});
}

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

Assert.That(ex.Message, Is.EqualTo("Test Message"));
}

[Test]
public void InvalidMessageWithTextAndInnerTest()
{
InvalidMessageException ex = Assert.Throws<InvalidMessageException>(() =>
{
throw new InvalidMessageException("Test Message Too", new System.Exception());
});

Assert.That(ex.Message, Is.EqualTo("Test Message Too"));
Assert.That(ex.InnerException, Is.TypeOf(typeof(System.Exception)));
}
}
}
11 changes: 11 additions & 0 deletions Assets/Tests/Editor/InvalidMessageExceptionTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Assets/Tests/Editor/NetworkIdentityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using UnityEngine.Events;

using static Mirror.Tests.LocalConnections;
using System.IO;

namespace Mirror.Tests
{
Expand Down Expand Up @@ -653,7 +652,7 @@ public void OnDeserializeSafelyShouldDetectAndHandleDeSerializationMismatch()

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

0 comments on commit 229f73d

Please sign in to comment.