Skip to content

fix: Harden error handling - #4161

Open
EmandM wants to merge 1 commit into
develop-3.x.xfrom
fix/error-handling
Open

EmandM wants to merge 1 commit into
develop-3.x.xfrom
fix/error-handling

Conversation

@EmandM

@EmandM EmandM commented Sep 15, 2026

Copy link
Copy Markdown
Member

Purpose of this PR

Ensure as many callbacks as possible are wrapped in try/catch blocks to avoid user generated errors throwing into internal netcode functionality.

Jira ticket

Reported internally.

Changelog

  • Fixed: Ensures all callbacks are wrapped with exception handling to avoid silent errors.

Documentation

  • No documentation changes or additions were necessary.

Testing & QA (How your changes can be verified during release Playtest)

Functional Testing

Manual testing :

  • Manual testing done

Automated tests:

  • Covered by existing automated tests
  • Covered by new automated tests

Does the change require QA team to:

  • Review automated tests?
  • Execute manual tests?
  • Provide feedback about the PR?

If any boxes above are checked the QA team will be automatically added as a PR reviewer.

Up-port

not needed

Backports

Might be worth a backport?

@EmandM
EmandM requested a review from a team as a code owner September 15, 2026 22:21
@u-pr

u-pr Bot commented Sep 15, 2026

Copy link
Copy Markdown

⚠️ Some settings were ignored in '.pr_agent.toml (repository root)' repo settings

Check the configuration's TOML syntax, permitted settings, and size limit. See the error below.


Error message:
Ignored prohibited settings: github_app.handle_pr_actions. Permitted settings were applied.

Configuration content:
# This is the configuration for the u-pr bot
# https://github.cds.internal.unity3d.com/unity/u-pr
# For configuration of this file:
# https://developer.portal.internal.unity.com/catalog/default/component/u-pr/docs/configuration/automatic_runs/

[github_app]
handle_pr_actions = ['opened', 'ready_for_review']  # PR events that auto-run pr_commands
pr_commands       = ["/harness-review"]             # what runs on those events
reviewer_commands = ["/harness-review"]             # what runs when @u-pr is added as reviewer

@u-pr u-pr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Harness Review

Needs changes

This broadly hardens user callback execution, but several exception paths change observable ownership and visibility behavior, and some shared exception boundaries still suppress later lifecycle notifications.

Reviewed commit c319570

🤖 Helpful? 👍/👎

{
try
{
OnOwnershipPermissionsFailure?.Invoke(OwnershipPermissionsFailureStatus.SessionOwnerOnly);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1

This helper discards the actual failure reason: every caller now reports SessionOwnerOnly. For example, the locked and request-required branches in ChangeOwnership both reach this method, although the public callback and existing ownership tests distinguish Locked and RequestRequired. Accept the status as a parameter and forward it from each of the five call sites.

🤖 Helpful? 👍/👎

catch (Exception ex)
{
Debug.LogException(ex);
return true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1

A configured visibility predicate that throws now grants visibility to that client. NetworkShow, observer setup, connection approval synchronization, and new-client observer updates all consume this return value, so an exception in a predicate intended to hide a private object can add the client as an observer and serialize its spawn/state. Keep the no-handler default as visible, but fail closed (false) when an installed predicate fails.

🤖 Helpful? 👍/👎

OnStarted?.Invoke();
try
{
OnServerStarted?.Invoke();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1

This catch covers three independent lifecycle notifications. On a host, an exception from an OnServerStarted subscriber skips OnClientStarted and OnStarted, even though startup continues successfully after the catch. The same shared-boundary problem occurs in the client/server start and stop paths, as well as where scene generic and specialized callbacks are paired. Invoke each distinct event behind its own exception boundary so one notification cannot suppress the others.

🤖 Helpful? 👍/👎

OnStarted?.Invoke();
try
{
OnServerStarted?.Invoke();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1

This changes the result covered by the existing NetworkManagerStartExceptionTests: it subscribes throwing OnServerStarted/OnClientStarted handlers and asserts that server, host, and client startup return false and tear down the transport. With this catch, these starts now return successfully, but the test was not updated, so that test suite will fail. Update its expectations and cleanup assertions to the new hardening contract (or retain the previous startup-failure behavior).

🤖 Helpful? 👍/👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant