Skip to content

stability improvement#10

Open
noverd wants to merge 1 commit intomainfrom
stability_imp_2025-07-17
Open

stability improvement#10
noverd wants to merge 1 commit intomainfrom
stability_imp_2025-07-17

Conversation

@noverd
Copy link
Owner

@noverd noverd commented Jul 17, 2025

title 🥇

  • Add finalizers to patches
  • Add build test
  • Remove LocalPlayerAddCompSystem with generic and replace with type-checking systems

Summary by Sourcery

Add Harmony finalizers for robust error handling in patches, streamline patch definitions, and standardize class modifiers to improve client stability

Enhancements:

  • Add HarmonyFinalizer methods with fatal logging to all patch classes
  • Simplify HarmonyPatch usage by specifying target in attributes and remove redundant TargetMethod methods
  • Standardize patch class access modifiers to internal and unify prefix method visibility

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 17, 2025

Reviewer's Guide

This PR bolsters patch reliability by introducing HarmonyFinalizer hooks across all patches for exception logging, standardizes class and method access modifiers to internal/private for consistency, and streamlines patch declarations by specifying targets directly in the HarmonyPatch attributes.

Sequence diagram for exception handling in patch finalizers

sequenceDiagram
    participant PatchedMethod as Patched Method
    participant PatchClass as Patch Finalizer
    participant Logger as MarseyLogger
    PatchedMethod->>PatchClass: Exception thrown
    PatchClass->>Logger: Fatal($"Error while patching <PatchName>: {__exception}")
Loading

Class diagram for updated patch classes with HarmonyFinalizer

classDiagram
    class ConsoleHostPatch {
        +[HarmonyPatch("Robust.Client.Console.ClientConsoleHost", "CanExecute")]
        -Postfix(ref bool __result)
        -Finalizer(Exception __exception)
    }
    class ClientHeavyAttackPatch {
        +[HarmonyPatch(typeof(MeleeWeaponSystem), "ClientHeavyAttack")]
        -Prefix(ref EntityUid user, ...)
        -Finalizer(Exception __exception)
    }
    class DrawOcclusionDepthPatch {
        +[HarmonyPatch]
        -Prefix()
        -Finalizer(Exception __exception)
    }
    class GunUpdatePatch {
        +[HarmonyPatch(typeof(GunSystem), nameof(GunSystem.Update))]
        -Transpiler(IEnumerable<CodeInstruction> codes)
        -Finalizer(Exception __exception)
    }
    class ClientAdminManagerPatch {
        +[HarmonyPatch]
        -Prefix(ref bool __result)
        -Finalizer(Exception __exception)
    }
    class EntityMenuElementPatch {
        +[HarmonyPatch]
        -Prefix(EntityUid entity, EntityMenuElement __instance, ref string __result)
        -Finalizer(Exception __exception)
    }
    class ClientConGroupControllerPatch {
        +[HarmonyPatch]
        -Prefix(ref bool __result)
        -Finalizer(Exception __exception)
    }
    class MouseRotatorPatch {
        +[HarmonyPatch]
        -Prefix()
        -Finalizer(Exception __exception)
    }
    class OverlaysPatch {
        +[HarmonyPatch]
        -Prefix()
        -Finalizer(Exception __exception)
    }
Loading

File-Level Changes

Change Details Files
Add exception finalizers to all Harmony patches
  • Introduce [HarmonyFinalizer] methods logging exceptions via MarseyLogger.Fatal
Patches/ConsoleHostPatch.cs
Patches/ClientHeavyAttackPatch.cs
Patches/DrawOcclusionDepthPatch.cs
Patches/GunUpdatePatch.cs
Patches/ClientAdminManagerPatch.cs
Patches/EntityMenuElementPatch.cs
Patches/ClientConGroupControllerPatch.cs
Patches/MouseRotatorPatch.cs
Patches/OverlaysPatch.cs
Standardize access modifiers for patch classes and methods
  • Convert public patch classes to internal
  • Restrict prefix methods to private static
Patches/ClientHeavyAttackPatch.cs
Patches/GunUpdatePatch.cs
Patches/DrawOcclusionDepthPatch.cs
Streamline HarmonyPatch declarations
  • Specify target type and method directly in [HarmonyPatch] attribute
  • Remove unused HarmonyTargetMethod override
Patches/ConsoleHostPatch.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @noverd - I've reviewed your changes - here's some feedback:

  • Consider consolidating the repeated [HarmonyFinalizer] logging logic into a shared helper or base class to reduce boilerplate across all patches.
  • Verify that your finalizer signatures match Harmony’s expected signature (usually returning an Exception) so that errors are handled or propagated correctly.
  • Double-check that changing patch classes from public to internal doesn’t inadvertently break any external consumers or reflection-based lookups.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider consolidating the repeated [HarmonyFinalizer] logging logic into a shared helper or base class to reduce boilerplate across all patches.
- Verify that your finalizer signatures match Harmony’s expected signature (usually returning an Exception) so that errors are handled or propagated correctly.
- Double-check that changing patch classes from public to internal doesn’t inadvertently break any external consumers or reflection-based lookups.

## Individual Comments

### Comment 1
<location> `ArabicaCliento/Patches/ConsoleHostPatch.cs:13` </location>
<code_context>
     }
+    
+        
+    [HarmonyFinalizer]
+    private static void Finalizer(Exception __exception)
+    {
</code_context>

<issue_to_address>
Finalizer logs all exceptions, which may mask original errors.

Logging without rethrowing may suppress important exceptions and hide bugs. Consider rethrowing after logging or handling only specific exceptions.
</issue_to_address>

### Comment 2
<location> `ArabicaCliento/Patches/DrawOcclusionDepthPatch.cs:14` </location>
<code_context>
     }
+    
+        
+    [HarmonyFinalizer]
+    private static void Finalizer(Exception __exception)
+    {
</code_context>

<issue_to_address>
Finalizer logs exceptions but does not handle or rethrow them.

Consider rethrowing the exception after logging to prevent silent failures and ensure errors are not masked.
</issue_to_address>

### Comment 3
<location> `ArabicaCliento/Patches/GunUpdatePatch.cs:61` </location>
<code_context>
     }
+    
+        
+    [HarmonyFinalizer]
+    private static void Finalizer(Exception __exception)
+    {
</code_context>

<issue_to_address>
Finalizer logs exceptions but does not rethrow.

Evaluate if rethrowing exceptions after logging is necessary to ensure important errors are not silently ignored.
</issue_to_address>

### Comment 4
<location> `ArabicaCliento/Patches/ClientAdminManagerPatch.cs:28` </location>
<code_context>
     }
+    
+        
+    [HarmonyFinalizer]
+    private static void Finalizer(Exception __exception)
+    {
+        MarseyLogger.Fatal($"Error while patching ClientAdminManagerPatch: {__exception}");
+    }
 }
</code_context>

<issue_to_address>
Finalizer logs exceptions but does not rethrow.

Suppressing exceptions in the finalizer may conceal errors. Consider rethrowing after logging if needed.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +13 to +16
[HarmonyFinalizer]
private static void Finalizer(Exception __exception)
{
MarseyLogger.Fatal($"Error while patching ConsoleHostPatch: {__exception}");
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Finalizer logs all exceptions, which may mask original errors.

Logging without rethrowing may suppress important exceptions and hide bugs. Consider rethrowing after logging or handling only specific exceptions.

Comment on lines +14 to +17
[HarmonyFinalizer]
private static void Finalizer(Exception __exception)
{
MarseyLogger.Fatal($"Error while patching DrawOcclusionDepthPatch: {__exception}");
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Finalizer logs exceptions but does not handle or rethrow them.

Consider rethrowing the exception after logging to prevent silent failures and ensure errors are not masked.

Comment on lines +61 to +64
[HarmonyFinalizer]
private static void Finalizer(Exception __exception)
{
MarseyLogger.Fatal($"Error while patching GunUpdatePatch: {__exception}");
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Finalizer logs exceptions but does not rethrow.

Evaluate if rethrowing exceptions after logging is necessary to ensure important errors are not silently ignored.

Comment on lines +28 to +31
[HarmonyFinalizer]
private static void Finalizer(Exception __exception)
{
MarseyLogger.Fatal($"Error while patching ClientAdminManagerPatch: {__exception}");
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Finalizer logs exceptions but does not rethrow.

Suppressing exceptions in the finalizer may conceal errors. Consider rethrowing after logging if needed.

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

Comments