[deep-review][duplication] D2: 106 empty try/catch blocks across 41 files (AI-slop pattern)
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 oftry { DispatcherQueue?.TryEnqueue(...) } catch { }.TryEnqueuedoesn't throw. The try/catch is doing nothing.src/OpenClaw.Tray.WinUI/Services/AudioPipeline.cs— 11 instances aroundDiagnosticMessage?.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:
- 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.
- Encourages copy-paste growth. Each new caller of
DispatcherQueuewraps in try/catch by reflex; the pattern proliferates. - 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:
- Land the helpers.
- Migrate the 26 HubWindow + AudioPipeline sites in one PR.
- Migrate the rest opportunistically.
- 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."
🤖 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—SafeEnqueueextension onDispatcherQueue?(no try/catch, since TryEnqueue returns bool)Helpers/SafeEventInvoke.cs—SafeInvoke<T>andSafeInvokeextensions that log aWarnwhen a handler throws instead of swallowing silentlyHubWindow.xaml.cs— removed 15 emptytry { DispatcherQueue?.TryEnqueue(...) } catch { }blocksAudioPipeline.cs— replaced 11 silent event swallows withSafeInvoke(..., _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.netvortex.data.microsoft.comTo allow these domains, add them to the
network.allowedlist 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
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.