openclaw-windows-node icon indicating copy to clipboard operation
openclaw-windows-node copied to clipboard

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

Open codemonkeychris opened this issue 6 months ago • 2 comments

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."

codemonkeychris avatar May 14 '26 00:05 codemonkeychris

🤖 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

github-actions[bot] avatar May 15 '26 01:05 github-actions[bot]

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.

shanselman avatar May 18 '26 00:05 shanselman