-
Notifications
You must be signed in to change notification settings - Fork 463
chore: started replacing exceptions #3867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop-2.0.0
Are you sure you want to change the base?
Changes from all commits
2e4f489
78b50c7
667b22f
9a0b665
3e0cffb
90b5dd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1458,7 +1458,10 @@ internal NetworkSceneHandle GetSceneOriginHandle() | |
| { | ||
| if (SceneOriginHandle.IsEmpty() && IsSpawned && IsSceneObject != false) | ||
| { | ||
| throw new Exception($"{nameof(GetSceneOriginHandle)} called when {nameof(SceneOriginHandle)} is still zero but the {nameof(NetworkObject)} is already spawned!"); | ||
| if (NetworkManager.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogErrorServer($"{nameof(GetSceneOriginHandle)} called when {nameof(SceneOriginHandle)} is still zero but the {nameof(NetworkObject)} is already spawned!"); | ||
| } | ||
| } | ||
| return !SceneOriginHandle.IsEmpty() ? SceneOriginHandle : gameObject.scene.handle; | ||
| } | ||
|
|
@@ -1481,31 +1484,50 @@ public void NetworkShow(ulong clientId) | |
| { | ||
| if (!IsSpawned) | ||
| { | ||
| throw new SpawnStateException("Object is not spawned"); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogErrorServer($"[{name}] Attempted NetworkShow while not spawned."); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if (!HasAuthority) | ||
| { | ||
| if (NetworkManagerOwner.DistributedAuthorityMode) | ||
| { | ||
| throw new NotServerException($"Only the owner-authority can change visibility when distributed authority mode is enabled!"); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogError($"[{name}] Only the owner-authority can change visibility when distributed authority mode is enabled!"); | ||
| } | ||
| return; | ||
| } | ||
| else | ||
| { | ||
| throw new NotServerException("Only the authority can change visibility"); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogError($"[{name}] Only the authority can change visibility."); | ||
| } | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| if (Observers.Contains(clientId)) | ||
| { | ||
| if (NetworkManagerOwner.DistributedAuthorityMode) | ||
| { | ||
| Debug.LogError($"The object {name} is already visible to Client-{clientId}!"); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogErrorServer($"The object {name} is already visible to Client-{clientId}!"); | ||
| } | ||
| return; | ||
| } | ||
| else | ||
| { | ||
| throw new NotServerException("Only server can change visibility"); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogError($"[{name}] Only the server can change visibility."); | ||
| } | ||
| return; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1568,18 +1590,30 @@ public void NetworkHide(ulong clientId) | |
| { | ||
| if (!IsSpawned) | ||
| { | ||
| throw new SpawnStateException("Object is not spawned"); | ||
| if (NetworkManager.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogErrorServer($"[{name}] Attempted NetworkHide while {nameof(NetworkObject)} is not spawned."); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if (!HasAuthority && !NetworkManagerOwner.DAHost) | ||
| { | ||
| if (NetworkManagerOwner.DistributedAuthorityMode) | ||
| { | ||
| throw new NotServerException($"Only the owner-authority can change visibility when distributed authority mode is enabled!"); | ||
| if (NetworkManager.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogError($"[{name}] Only the owner-authority can change visibility when distributed authority mode is enabled!"); | ||
| } | ||
| return; | ||
| } | ||
| else | ||
| { | ||
| throw new NotServerException("Only the authority can change visibility"); | ||
| if (NetworkManager.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogError($"[{name}] Only the authority can change visibility!"); | ||
| } | ||
| return; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1589,9 +1623,9 @@ public void NetworkHide(ulong clientId) | |
| { | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Developer) | ||
| { | ||
| Debug.LogWarning($"{name} is already hidden from Client-{clientId}! (ignoring)"); | ||
| return; | ||
| NetworkLog.LogWarning($"[{name}] {nameof(NetworkObject)} already hidden from Client-{clientId}! (ignoring)"); | ||
| } | ||
| return; | ||
| } | ||
| Observers.Remove(clientId); | ||
|
|
||
|
|
@@ -1724,18 +1758,30 @@ internal void SpawnInternal(bool destroyWithScene, ulong ownerClientId, bool pla | |
|
|
||
| if (!NetworkManagerOwner.IsListening) | ||
| { | ||
| throw new NotListeningException($"{nameof(NetworkManagerOwner)} is not listening, start a server or host before spawning objects"); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogError($"[{name}] {nameof(NetworkManagerOwner)} is not listening, start a server or host before spawning objects."); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if ((!NetworkManagerOwner.IsServer && !NetworkManagerOwner.DistributedAuthorityMode) || (NetworkManagerOwner.DistributedAuthorityMode && !NetworkManagerOwner.LocalClient.IsSessionOwner && NetworkManagerOwner.LocalClientId != ownerClientId)) | ||
| { | ||
| if (NetworkManagerOwner.DistributedAuthorityMode) | ||
| { | ||
| throw new NotServerException($"When distributed authority mode is enabled, you can only spawn NetworkObjects that belong to the local instance! Local instance id {NetworkManagerOwner.LocalClientId} is not the same as the assigned owner id: {ownerClientId}!"); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogError($"[{name}] When distributed authority mode is enabled, you can only spawn NetworkObjects that belong to the local instance! Local instance id {NetworkManagerOwner.LocalClientId} is not the same as the assigned owner id: {ownerClientId}!"); | ||
| } | ||
| return; | ||
| } | ||
| else | ||
| { | ||
| throw new NotServerException($"Only server can spawn {nameof(NetworkObject)}s"); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogError($"[{name}] Only server can spawn {nameof(NetworkObject)}s."); | ||
| } | ||
| return; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -2256,7 +2302,10 @@ private void OnTransformParentChanged() | |
| return; | ||
| } | ||
| transform.parent = m_CachedParent; | ||
| Debug.LogException(new NotListeningException($"[{name}] {nameof(networkManager)} is not listening, start a server or host before re-parenting")); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogError($"[{name}] {nameof(networkManager)} is not listening, start a server or host before re-parenting."); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -2273,7 +2322,10 @@ private void OnTransformParentChanged() | |
| else | ||
| { | ||
| transform.parent = m_CachedParent; | ||
| Debug.LogException(new SpawnStateException($"[{name}] {nameof(NetworkObject)} can only be re-parented after being spawned")); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogErrorServer($"[{name}] {nameof(NetworkObject)} can only be re-parented after being spawned!"); | ||
| } | ||
| } | ||
| return; | ||
| } | ||
|
|
@@ -2293,7 +2345,7 @@ private void OnTransformParentChanged() | |
| } | ||
| else | ||
| { | ||
| Debug.LogException(new NotServerException($"[{name}] Only the server can re-parent {nameof(NetworkObject)}s")); | ||
| NetworkLog.LogError($"[{name}] Only the server can re-parent {nameof(NetworkObject)}s."); | ||
| } | ||
| } | ||
| return; | ||
|
|
@@ -2307,14 +2359,20 @@ private void OnTransformParentChanged() | |
| { | ||
| transform.parent = m_CachedParent; | ||
| AuthorityAppliedParenting = false; | ||
| Debug.LogException(new InvalidParentException($"[{name}] Invalid parenting, {nameof(NetworkObject)} moved under a non-{nameof(NetworkObject)} parent")); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogErrorServer($"[{name}] Invalid parenting, {nameof(NetworkObject)} moved under a non-{nameof(NetworkObject)} parent"); | ||
| } | ||
| return; | ||
| } | ||
| else if (!parentObject.IsSpawned) | ||
| { | ||
| transform.parent = m_CachedParent; | ||
| AuthorityAppliedParenting = false; | ||
| Debug.LogException(new SpawnStateException($"[{name}] {nameof(NetworkObject)} can only be re-parented under another spawned {nameof(NetworkObject)}")); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogErrorServer($"[{name}] {nameof(NetworkObject)} can only be re-parented under another spawned {nameof(NetworkObject)}."); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -2536,7 +2594,10 @@ internal void InvokeBehaviourNetworkSpawn() | |
| { | ||
| if (!childBehaviour.gameObject.activeInHierarchy) | ||
| { | ||
| Debug.LogWarning($"{GenerateDisabledNetworkBehaviourWarning(childBehaviour)}"); | ||
| if (NetworkManagerOwner.LogLevel <= LogLevel.Developer) | ||
| { | ||
| NetworkLog.LogWarning($"{GenerateDisabledNetworkBehaviourWarning(childBehaviour)}"); | ||
| } | ||
| continue; | ||
| } | ||
| childBehaviour.InternalOnNetworkSpawn(); | ||
|
|
@@ -2992,7 +3053,10 @@ public void Serialize(FastBufferWriter writer) | |
|
|
||
| if (!writer.TryBeginWrite(writeSize)) | ||
| { | ||
| throw new OverflowException("Could not serialize SceneObject: Out of buffer space."); | ||
| if (NetworkManager.Singleton.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogError("Could not serialize NetworkObject: Out of buffer space."); | ||
| } | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't catch why we didn't want to add a return here, is it correct not to add one for throwing an overflow exception?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I got mixed up. I was saying maybe we leave the exceptions in. I'll check with Noel what we want the behaviour to be here. |
||
| } | ||
|
|
||
| if (HasTransform) | ||
|
|
@@ -3079,7 +3143,10 @@ public void Deserialize(FastBufferReader reader) | |
| // Try to begin reading the remaining bytes | ||
| if (!reader.TryBeginRead(readSize)) | ||
| { | ||
| throw new OverflowException("Could not deserialize SceneObject: Reading past the end of the buffer"); | ||
| if (NetworkManager.Singleton.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogError("Could not deserialize NetworkObject: Reading past the end of the buffer."); | ||
| } | ||
| } | ||
|
|
||
| if (HasTransform) | ||
|
|
@@ -3327,7 +3394,11 @@ internal static NetworkObject Deserialize(in SerializedObject serializedObject, | |
| // Spawn the NetworkObject | ||
| if (networkObject.IsSpawned) | ||
| { | ||
| throw new SpawnStateException($"[{networkObject.name}] Object-{networkObject.NetworkObjectId} is already spawned!"); | ||
| if (NetworkManager.Singleton.LogLevel <= LogLevel.Error) | ||
| { | ||
| NetworkLog.LogErrorServer($"[{networkObject.name}] Object-{networkObject.NetworkObjectId} is already spawned!"); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| // Invoke the non-authority local spawn method | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer to not use the Singleton in our internal code because the integration tests run with multiple NetworkManagers running at the same time. That means we need to be sure that the right NetworkManager is being used in each place. In this spot you can access the correct NetworkManager using
OwnerObject.NetworkManagerOwner.