Skip to content

[deep-review][duplication] D2: 106 empty try/catch blocks across 41 files (AI-slop pattern) #365

Closed

Description

@codemonkeychris

Summary

Grep across src/ finds 106 instances of catch { } (or catch (Exception) { /* ignore */ }) across 41 files. Many are around method calls that don't throw (DispatcherQueue?.TryEnqueue returns false on failure rather than throwing), and many cluster in the same file with the same shape — strong AI-assisted-edit fingerprint.

Highest concentrations:

  • src/OpenClaw.Tray.WinUI/Windows/HubWindow.xaml.cs — 15 instances of try { DispatcherQueue?.TryEnqueue(...) } catch { }. TryEnqueue doesn't throw. The try/catch is doing nothing.
  • src/OpenClaw.Tray.WinUI/Services/AudioPipeline.cs — 11 instances around DiagnosticMessage?.Invoke(...). The invoke can throw if a handler throws; the swallow loses the exception.
  • src/OpenClaw.Tray.WinUI/Services/NodeService.Dispose — 11 instances (code-quality review).

Why it matters

Three concrete problems:

  1. Hides real exceptions. When a handler genuinely faults, the swallow makes diagnosis impossible. The bug report is "the activity stream randomly stops updating" with nothing in the log.
  2. Encourages copy-paste growth. Each new caller of DispatcherQueue wraps in try/catch by reflex; the pattern proliferates.
  3. Conceals real intent. Was the catch defensive (handler-might-throw) or paranoid (TryEnqueue-might-throw)? The reader can't tell without auditing every site.

Proposed fix

Two helper methods:

public static class SafeDispatch
{
    // Use when calling DispatcherQueue.TryEnqueue
    public static void SafeEnqueue(this DispatcherQueue? q, DispatcherQueueHandler action);

    // Use when invoking an event with possibly-throwing handlers
    public static void SafeInvoke<TArgs>(this EventHandler<TArgs>? handler, object sender, TArgs args, IOpenClawLogger? log = null);
}

SafeInvoke logs at Warn when a handler throws, identifying the handler by MethodBase.GetCurrentMethod() or similar.

Migration:

  1. Land the helpers.
  2. Migrate the 26 HubWindow + AudioPipeline sites in one PR.
  3. Migrate the rest opportunistically.
  4. Add an analyzer or grep CI check: empty catches in src/ should be exceptional and commented with why.

Severity

Medium — observable as "rare bugs that can't be reproduced."

Activity

  1. added
    bug
    on May 14, 2026
  2. added a commit that references this issue on May 15, 2026
    aeed3f3
  3. github-actions commented on May 15, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    I've created a PR that implements steps 1 and 2 of the proposed migration:

    • Helpers/SafeDispatch.cs — SafeEnqueue extension on DispatcherQueue? (no try/catch, since TryEnqueue returns bool)
    • Helpers/SafeEventInvoke.cs — SafeInvoke<T> and SafeInvoke extensions that log a Warn when a handler throws instead of swallowing silently
    • HubWindow.xaml.cs — removed 15 empty try { DispatcherQueue?.TryEnqueue(...) } catch { } blocks
    • AudioPipeline.cs — replaced 11 silent event swallows with SafeInvoke(..., _logger)
    • 9 new unit tests covering null-safety, multi-handler firing, exception containment, and logger integration

    The remaining ~80 sites across 39 other files are left for opportunistic follow-up as the issue proposes. The PR is on branch repo-assist/fix-safe-dispatch-empty-catches-365.

    Warning

    Firewall blocked 2 domains

    The following domains were blocked by the firewall during workflow execution:

    • az667904.vo.msecnd.net
    • vortex.data.microsoft.com

    To allow these domains, add them to the network.allowed list in your workflow frontmatter:

    network:
      allowed:
        - defaults
        - "az667904.vo.msecnd.net"
        - "vortex.data.microsoft.com"

    See Network Configuration for more information.

    Generated by 🌈 Repo Assist, see workflow run. Learn more.

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a
    
  4. shanselman commented on May 18, 2026

    @shanselman
    Collaborator

    Closing during the post-refactor deep-review cleanup. Empty-catch cleanup is rescoped to source-only work in #372; stale broad automation PR was closed. This keeps the signal while reducing stale one-off issue noise.

  5. locked as resolved and limited conversation to collaborators on May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrefactor

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions