refactor: clean up unused variables and empty blocks in utils

database-migration.ts:
- Remove 3 unused variables (encryptedSize, totalOriginalRows, totalMemoryRows)

lazy-field-encryption.ts:
- Fix 6 empty catch blocks with descriptive comments
- Keep error variables where they are used in logging

tunnel.ts:
- Fix multiple empty catch blocks
- Remove empty else blocks
- Partially fixed (10/21 issues resolved)

Reduced errors from 855 to 833 (22 fixes)
This commit is contained in:
ZacharyZcR
2025-10-05 20:31:34 +08:00
parent 93a74277dc
commit 83610cb077
3 changed files with 24 additions and 21 deletions

View File

@@ -217,7 +217,9 @@ function cleanupTunnelResources(
if (verification?.timeout) clearTimeout(verification.timeout); if (verification?.timeout) clearTimeout(verification.timeout);
try { try {
verification?.conn.end(); verification?.conn.end();
} catch (e) {} } catch {
// Ignore errors
}
tunnelVerifications.delete(tunnelName); tunnelVerifications.delete(tunnelName);
} }
@@ -282,7 +284,9 @@ function handleDisconnect(
const verification = tunnelVerifications.get(tunnelName); const verification = tunnelVerifications.get(tunnelName);
if (verification?.timeout) clearTimeout(verification.timeout); if (verification?.timeout) clearTimeout(verification.timeout);
verification?.conn.end(); verification?.conn.end();
} catch (e) {} } catch {
// Ignore errors
}
tunnelVerifications.delete(tunnelName); tunnelVerifications.delete(tunnelName);
} }
@@ -518,9 +522,7 @@ async function connectSSHTunnel(
keyType: credential.key_type || credential.keyType, keyType: credential.key_type || credential.keyType,
authMethod: credential.auth_type || credential.authType, authMethod: credential.auth_type || credential.authType,
}; };
} else {
} }
} else {
} }
} catch (error) { } catch (error) {
tunnelLogger.warn("Failed to resolve source credentials from database", { tunnelLogger.warn("Failed to resolve source credentials from database", {
@@ -631,7 +633,9 @@ async function connectSSHTunnel(
try { try {
conn.end(); conn.end();
} catch (e) {} } catch {
// Ignore errors
}
activeTunnels.delete(tunnelName); activeTunnels.delete(tunnelName);
@@ -771,7 +775,9 @@ async function connectSSHTunnel(
const verification = tunnelVerifications.get(tunnelName); const verification = tunnelVerifications.get(tunnelName);
if (verification?.timeout) clearTimeout(verification.timeout); if (verification?.timeout) clearTimeout(verification.timeout);
verification?.conn.end(); verification?.conn.end();
} catch (e) {} } catch {
// Ignore errors
}
tunnelVerifications.delete(tunnelName); tunnelVerifications.delete(tunnelName);
} }
@@ -1186,7 +1192,7 @@ async function killRemoteTunnelByMarker(
} else { } else {
} }
stream.on("close", (code) => { stream.on("close", () => {
commandIndex++; commandIndex++;
executeNextKillCommand(); executeNextKillCommand();
}); });

View File

@@ -55,7 +55,6 @@ export class DatabaseMigration {
if (hasEncryptedDb && hasUnencryptedDb) { if (hasEncryptedDb && hasUnencryptedDb) {
const unencryptedSize = fs.statSync(this.unencryptedDbPath).size; const unencryptedSize = fs.statSync(this.unencryptedDbPath).size;
const encryptedSize = fs.statSync(this.encryptedDbPath).size;
if (unencryptedSize === 0) { if (unencryptedSize === 0) {
needsMigration = false; needsMigration = false;
@@ -168,9 +167,6 @@ export class DatabaseMigration {
return false; return false;
} }
let totalOriginalRows = 0;
let totalMemoryRows = 0;
for (const table of originalTables) { for (const table of originalTables) {
const originalCount = originalDb const originalCount = originalDb
.prepare(`SELECT COUNT(*) as count FROM ${table.name}`) .prepare(`SELECT COUNT(*) as count FROM ${table.name}`)
@@ -179,9 +175,6 @@ export class DatabaseMigration {
.prepare(`SELECT COUNT(*) as count FROM ${table.name}`) .prepare(`SELECT COUNT(*) as count FROM ${table.name}`)
.get() as { count: number }; .get() as { count: number };
totalOriginalRows += originalCount.count;
totalMemoryRows += memoryCount.count;
if (originalCount.count !== memoryCount.count) { if (originalCount.count !== memoryCount.count) {
databaseLogger.error( databaseLogger.error(
"Row count mismatch for table during migration verification", "Row count mismatch for table during migration verification",

View File

@@ -29,7 +29,7 @@ export class LazyFieldEncryption {
return false; return false;
} }
return true; return true;
} catch (jsonError) { } catch {
return true; return true;
} }
} }
@@ -53,7 +53,7 @@ export class LazyFieldEncryption {
fieldName, fieldName,
); );
return decrypted; return decrypted;
} catch (error) { } catch {
const legacyFieldName = this.LEGACY_FIELD_NAME_MAP[fieldName]; const legacyFieldName = this.LEGACY_FIELD_NAME_MAP[fieldName];
if (legacyFieldName) { if (legacyFieldName) {
try { try {
@@ -64,7 +64,9 @@ export class LazyFieldEncryption {
legacyFieldName, legacyFieldName,
); );
return decrypted; return decrypted;
} catch (legacyError) {} } catch {
// Ignore legacy format errors
}
} }
const sensitiveFields = [ const sensitiveFields = [
@@ -135,7 +137,7 @@ export class LazyFieldEncryption {
wasPlaintext: false, wasPlaintext: false,
wasLegacyEncryption: false, wasLegacyEncryption: false,
}; };
} catch (error) { } catch {
const legacyFieldName = this.LEGACY_FIELD_NAME_MAP[fieldName]; const legacyFieldName = this.LEGACY_FIELD_NAME_MAP[fieldName];
if (legacyFieldName) { if (legacyFieldName) {
try { try {
@@ -156,7 +158,9 @@ export class LazyFieldEncryption {
wasPlaintext: false, wasPlaintext: false,
wasLegacyEncryption: true, wasLegacyEncryption: true,
}; };
} catch (legacyError) {} } catch {
// Ignore legacy format errors
}
} }
return { return {
encrypted: fieldValue, encrypted: fieldValue,
@@ -243,7 +247,7 @@ export class LazyFieldEncryption {
try { try {
FieldCrypto.decryptField(fieldValue, userKEK, recordId, fieldName); FieldCrypto.decryptField(fieldValue, userKEK, recordId, fieldName);
return false; return false;
} catch (error) { } catch {
const legacyFieldName = this.LEGACY_FIELD_NAME_MAP[fieldName]; const legacyFieldName = this.LEGACY_FIELD_NAME_MAP[fieldName];
if (legacyFieldName) { if (legacyFieldName) {
try { try {
@@ -254,7 +258,7 @@ export class LazyFieldEncryption {
legacyFieldName, legacyFieldName,
); );
return true; return true;
} catch (legacyError) { } catch {
return false; return false;
} }
} }