Skip to content

Commit d23f8ca

Browse files
authored
Harden and annotate Slopwatch findings (#716)
Merged Slopwatch hardening and audited inline suppressions.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d1b1363 commit d23f8ca

135 files changed

Lines changed: 567 additions & 97 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/OpenClaw.Connection/GatewayConnectionManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ tunnel.SshPort is < 1 or > 65535 ||
289289
{
290290
await lifecycle.ConnectAsync(ct);
291291
}
292+
// slopwatch-ignore: SW003 Shutdown cancellation or disposal is expected and the caller already preserves the safe state.
292293
catch (OperationCanceledException) { }
293294
catch (Exception ex)
294295
{
@@ -654,6 +655,7 @@ private bool TryScheduleOperatorTokenRecovery(string message, long gen)
654655
if (Interlocked.Read(ref _generation) != gen || _disposed) return;
655656
await ReconnectAsync();
656657
}
658+
// slopwatch-ignore: SW003 Shutdown cancellation or disposal is expected and the caller already preserves the safe state.
657659
catch (ObjectDisposedException) { }
658660
catch (Exception ex)
659661
{
@@ -1239,6 +1241,7 @@ private async Task DisposeCoreAsync()
12391241
{
12401242
if (semaphoreEntered)
12411243
{
1244+
// slopwatch-ignore: SW003 Cleanup is best-effort; failure cannot improve caller state and the original outcome is preserved.
12421245
try { _transitionSemaphore.Release(); } catch { }
12431246
_transitionSemaphore.Dispose();
12441247
}

src/OpenClaw.Connection/GatewayRegistry.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public sealed class GatewayRegistry
1313
private readonly string _filePath;
1414
private readonly string _gatewaysDir;
1515
private readonly IFileSystem _fs;
16+
private readonly IOpenClawLogger _logger;
1617
private List<GatewayRecord> _records = [];
1718
private string? _activeId;
1819

@@ -29,9 +30,11 @@ public sealed class GatewayRegistry
2930
/// </summary>
3031
/// <param name="dataDir">Root data directory (e.g. %APPDATA%/OpenClawTray).</param>
3132
/// <param name="fs">Filesystem abstraction for testability.</param>
32-
public GatewayRegistry(string dataDir, IFileSystem? fs = null)
33+
/// <param name="logger">Optional diagnostics sink for persistence problems.</param>
34+
public GatewayRegistry(string dataDir, IFileSystem? fs = null, IOpenClawLogger? logger = null)
3335
{
3436
_fs = fs ?? RealFileSystem.Instance;
37+
_logger = logger ?? NullLogger.Instance;
3538
_filePath = Path.Combine(dataDir, "gateways.json");
3639
_gatewaysDir = Path.Combine(dataDir, "gateways");
3740
}
@@ -164,9 +167,9 @@ public void Load()
164167
}
165168
}
166169
}
167-
catch (JsonException)
170+
catch (JsonException ex)
168171
{
169-
// Corrupted file — start fresh
172+
_logger.Warn($"Gateway registry file '{_filePath}' is not valid JSON; starting with an empty registry. {ex.Message}");
170173
}
171174
}
172175

src/OpenClaw.Connection/SshTunnelService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public void Stop()
106106
}
107107
finally
108108
{
109+
// slopwatch-ignore: SW003 Cleanup is best-effort; failure cannot improve caller state and the original outcome is preserved.
109110
try { _process.Dispose(); } catch { }
110111
_process = null;
111112
_lastSpec = null;
@@ -172,6 +173,7 @@ private void StartProcess(string user, string host, int remotePort, int localPor
172173
LastError = $"SSH tunnel exited unexpectedly with code {exitCode}.";
173174
StartedAtUtc = null;
174175
Status = TunnelStatus.Failed;
176+
// slopwatch-ignore: SW003 Cleanup is best-effort; failure cannot improve caller state and the original outcome is preserved.
175177
try { process.Dispose(); } catch { }
176178
_process = null;
177179
_lastSpec = null;

src/OpenClaw.SetupEngine.UI/LogFileLauncher.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static void RevealInExplorer(string? logPath)
6565
});
6666
}
6767
}
68+
// slopwatch-ignore: SW003 Audited non-critical fallback is intentional and the caller preserves safe behavior without this work.
6869
catch
6970
{
7071
// best effort — the link is informational

src/OpenClaw.SetupEngine.UI/Pages/PermissionsPage.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ private static FrameworkElement BuildRow(PermDef perm, string status, bool grant
106106
btn.Click += async (_, _) =>
107107
{
108108
try { await Windows.System.Launcher.LaunchUriAsync(new Uri(uri)); }
109+
// slopwatch-ignore: SW003 UI helper action is best-effort and failure should not break the owning UI flow.
109110
catch { /* best effort */ }
110111
};
111112
actionCol = btn;

src/OpenClaw.SetupEngine.UI/Pages/WizardPage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ private void StartConsoleTail()
626626
AppendConsoleLine(message);
627627
});
628628
}
629+
// slopwatch-ignore: SW003 Audited non-critical fallback is intentional and the caller preserves safe behavior without this work.
629630
catch
630631
{
631632
}
@@ -636,7 +637,9 @@ private void StopConsoleTail()
636637
{
637638
var tail = _consoleTail;
638639
_consoleTail = null;
640+
// slopwatch-ignore: SW003 Cleanup is best-effort; failure cannot improve caller state and the original outcome is preserved.
639641
try { tail?.Stop(); } catch { }
642+
// slopwatch-ignore: SW003 Cleanup is best-effort; failure cannot improve caller state and the original outcome is preserved.
640643
try { tail?.Dispose(); } catch { }
641644
}
642645

@@ -778,6 +781,7 @@ private async Task CancelCurrentSessionAsync()
778781
if (_client != null && !string.IsNullOrWhiteSpace(_sessionId))
779782
{
780783
try { await _client.SendWizardRequestAsync("wizard.cancel", new { sessionId = _sessionId }, timeoutMs: 10_000); }
784+
// slopwatch-ignore: SW003 Cleanup is best-effort; failure cannot improve caller state and the original outcome is preserved.
781785
catch { }
782786
}
783787
await DisconnectAsync();
@@ -809,6 +813,7 @@ private async Task DisconnectAsync()
809813
if (client == null) return;
810814
_client = null;
811815
client.StatusChanged -= OnWizardClientStatusChanged;
816+
// slopwatch-ignore: SW003 Cleanup is best-effort; failure cannot improve caller state and the original outcome is preserved.
812817
try { await client.DisconnectAsync(); } catch { }
813818
client.Dispose();
814819
}

src/OpenClaw.SetupEngine.UI/WizardConsoleTail.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public void Start(Action<string> onMessage)
8787
var extracted = TryExtractConsoleMessage(e.Data);
8888
if (extracted == null) return;
8989
try { onMessage(extracted); }
90+
// slopwatch-ignore: SW003 Cleanup is best-effort; failure cannot improve caller state and the original outcome is preserved.
9091
catch { /* never let a UI mistake kill the tail */ }
9192
};
9293
process.ErrorDataReceived += (_, e) =>
@@ -124,7 +125,9 @@ public void Stop()
124125
if (!process.HasExited)
125126
process.Kill(entireProcessTree: true);
126127
}
128+
// slopwatch-ignore: SW003 Cleanup is best-effort; failure cannot improve caller state and the original outcome is preserved.
127129
catch { /* already gone */ }
130+
// slopwatch-ignore: SW003 Cleanup is best-effort; failure cannot improve caller state and the original outcome is preserved.
128131
try { process.Dispose(); } catch { }
129132
}
130133

src/OpenClaw.SetupEngine/AtomicFile.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ private static void TryDeleteTemp(string tempPath)
5151
if (File.Exists(tempPath))
5252
File.Delete(tempPath);
5353
}
54-
catch
54+
catch (Exception ex)
5555
{
56+
System.Diagnostics.Debug.WriteLine($"Failed to delete temporary file '{tempPath}': {ex.Message}");
5657
}
5758
}
5859
}

src/OpenClaw.SetupEngine/CommandRunner.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public Task<CommandResult> RunInWslAsync(
176176

177177
private static void TryKill(Process process)
178178
{
179+
// slopwatch-ignore: SW003 Cleanup is best-effort; failure cannot improve caller state and the original outcome is preserved.
179180
try { process.Kill(entireProcessTree: true); } catch { /* best effort */ }
180181
}
181182

src/OpenClaw.SetupEngine/ExistingConfigDetector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public static ExistingConfig Detect(string dataDir, string targetDistroName)
5252
hasDistro = distros.Any(d => d.Equals(targetDistroName, StringComparison.OrdinalIgnoreCase));
5353
}
5454
}
55-
catch
55+
catch (Exception ex)
5656
{
57-
// WSL not available.
57+
System.Diagnostics.Debug.WriteLine($"WSL distro detection failed: {ex.Message}");
5858
}
5959

6060
var hasIdentity = false;

0 commit comments

Comments
 (0)