From f12c08845cc3cc51a1b9e316b83849bf12bb9a0f Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Sun, 5 Oct 2025 20:58:55 +0800 Subject: [PATCH] fix: clean up empty catch blocks in backend utilities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复了后端工具文件中的 10 个空 catch 块: - system-crypto.ts: 修复 1 个空 catch 块 - server-stats.ts: 修复 4 个空 catch 块 - auto-ssl-setup.ts: 修复 1 个空 catch 块 - ssh-key-utils.ts: 修复 4 个空 catch 块 所有空块都添加了描述性注释说明为何忽略错误。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/backend/ssh/server-stats.ts | 16 ++++++++++++---- src/backend/utils/auto-ssl-setup.ts | 4 +++- src/backend/utils/ssh-key-utils.ts | 16 ++++++++++++---- src/backend/utils/system-crypto.ts | 4 +++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/backend/ssh/server-stats.ts b/src/backend/ssh/server-stats.ts index 1dfd27e3..73911848 100644 --- a/src/backend/ssh/server-stats.ts +++ b/src/backend/ssh/server-stats.ts @@ -123,7 +123,9 @@ class SSHConnectionPool { if (!conn.inUse && now - conn.lastUsed > maxAge) { try { conn.client.end(); - } catch {} + } catch { + // Ignore errors when closing stale connections + } return false; } return true; @@ -143,7 +145,9 @@ class SSHConnectionPool { for (const conn of connections) { try { conn.client.end(); - } catch {} + } catch { + // Ignore errors when closing connections during cleanup + } } } this.connections.clear(); @@ -181,7 +185,9 @@ class RequestQueue { if (request) { try { await request(); - } catch (error) {} + } catch { + // Ignore errors from queued requests + } } } @@ -829,7 +835,9 @@ function tcpPing( settled = true; try { socket.destroy(); - } catch {} + } catch { + // Ignore errors when destroying socket + } resolve(result); }; diff --git a/src/backend/utils/auto-ssl-setup.ts b/src/backend/utils/auto-ssl-setup.ts index e2d1034a..5d9a6fc8 100644 --- a/src/backend/utils/auto-ssl-setup.ts +++ b/src/backend/utils/auto-ssl-setup.ts @@ -234,7 +234,9 @@ IP.3 = 0.0.0.0 let envContent = ""; try { envContent = await fs.readFile(this.ENV_FILE, "utf8"); - } catch {} + } catch { + // File doesn't exist yet, will create with SSL config + } let updatedContent = envContent; let hasChanges = false; diff --git a/src/backend/utils/ssh-key-utils.ts b/src/backend/utils/ssh-key-utils.ts index b19f95c9..9a9f813d 100644 --- a/src/backend/utils/ssh-key-utils.ts +++ b/src/backend/utils/ssh-key-utils.ts @@ -84,7 +84,9 @@ function detectKeyTypeFromContent(keyContent: string): string { } else if (decodedString.includes("1.3.101.112")) { return "ssh-ed25519"; } - } catch (error) {} + } catch { + // Cannot decode key, fallback to length-based detection + } if (content.length < 800) { return "ssh-ed25519"; @@ -140,7 +142,9 @@ function detectPublicKeyTypeFromContent(publicKeyContent: string): string { } else if (decodedString.includes("1.3.101.112")) { return "ssh-ed25519"; } - } catch (error) {} + } catch { + // Cannot decode key, fallback to length-based detection + } if (content.length < 400) { return "ssh-ed25519"; @@ -242,7 +246,9 @@ export function parseSSHKey( useSSH2 = true; } - } catch (error) {} + } catch { + // SSH2 parsing failed, will use fallback method + } } if (!useSSH2) { @@ -268,7 +274,9 @@ export function parseSSHKey( success: true, }; } - } catch (fallbackError) {} + } catch { + // Fallback parsing also failed + } return { privateKey: privateKeyData, diff --git a/src/backend/utils/system-crypto.ts b/src/backend/utils/system-crypto.ts index 689a3137..9f9c15b0 100644 --- a/src/backend/utils/system-crypto.ts +++ b/src/backend/utils/system-crypto.ts @@ -115,7 +115,9 @@ class SystemCrypto { process.env.INTERNAL_AUTH_TOKEN = tokenMatch[1]; return; } - } catch {} + } catch { + // Ignore file read errors, will generate new token + } await this.generateAndGuideInternalAuthToken(); } catch (error) {