fix: resolve all 301 error handling anti-patterns across codebase
Systematic cleanup of every error handling anti-pattern detected by the automated scanner. 289 issues fixed via code changes, 12 approved with specific technical justifications. Changes across 90 files: - GENERIC_CATCH (141): Added instanceof Error type discrimination - LARGE_TRY_BLOCK (82): Extracted helper methods to narrow try scope to ≤10 lines - NO_LOGGING_IN_CATCH (65): Added logger/console calls for error visibility - CATCH_AND_CONTINUE_CRITICAL_PATH (10): Added throw/return or approved overrides - ERROR_STRING_MATCHING (2): Approved with rationale (no typed error classes) - ERROR_MESSAGE_GUESSING (1): Replaced chained .includes() with documented pattern array - PROMISE_CATCH_NO_LOGGING (1): Added logging to .catch() handler Also fixes a detector bug where nested try/catch inside a catch block corrupted brace-depth tracking, causing false positives. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -78,6 +78,11 @@ export class ChromaMcpManager {
|
||||
await this.connecting;
|
||||
} catch (error) {
|
||||
this.lastConnectionFailureTimestamp = Date.now();
|
||||
if (error instanceof Error) {
|
||||
logger.error('CHROMA_MCP', 'Connection attempt failed', {}, error);
|
||||
} else {
|
||||
logger.error('CHROMA_MCP', 'Connection attempt failed with non-Error value', { error: String(error) });
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
this.connecting = null;
|
||||
@@ -307,9 +312,15 @@ export class ChromaMcpManager {
|
||||
// Try JSON parse first; if it fails, return the raw text for non-error responses.
|
||||
try {
|
||||
return JSON.parse(firstTextContent.text);
|
||||
} catch {
|
||||
} catch (parseError: unknown) {
|
||||
// Plain text response (e.g. "Successfully created collection cm__foo")
|
||||
// Return null for void-like success messages, callers don't need the text
|
||||
if (parseError instanceof Error) {
|
||||
logger.debug('CHROMA_MCP', 'Non-JSON response from tool, returning null', {
|
||||
toolName,
|
||||
textPreview: firstTextContent.text.slice(0, 100)
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -322,7 +333,10 @@ export class ChromaMcpManager {
|
||||
try {
|
||||
await this.callTool('chroma_list_collections', { limit: 1 });
|
||||
return true;
|
||||
} catch {
|
||||
} catch (error) {
|
||||
logger.warn('CHROMA_MCP', 'Health check failed', {
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -342,7 +356,11 @@ export class ChromaMcpManager {
|
||||
try {
|
||||
await this.client.close();
|
||||
} catch (error) {
|
||||
logger.debug('CHROMA_MCP', 'Error during client close (subprocess may already be dead)', {}, error as Error);
|
||||
if (error instanceof Error) {
|
||||
logger.debug('CHROMA_MCP', 'Error during client close (subprocess may already be dead)', {}, error);
|
||||
} else {
|
||||
logger.debug('CHROMA_MCP', 'Error during client close (subprocess may already be dead)', { error: String(error) });
|
||||
}
|
||||
}
|
||||
|
||||
getSupervisor().unregisterProcess(CHROMA_SUPERVISOR_ID);
|
||||
@@ -394,7 +412,10 @@ export class ChromaMcpManager {
|
||||
'uvx --with certifi python -c "import certifi; print(certifi.where())"',
|
||||
{ encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 10000 }
|
||||
).trim();
|
||||
} catch {
|
||||
} catch (error) {
|
||||
logger.debug('CHROMA_MCP', 'Failed to resolve certifi path via uvx', {
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -408,7 +429,10 @@ export class ChromaMcpManager {
|
||||
'security find-certificate -a -c "Zscaler" -p /Library/Keychains/System.keychain',
|
||||
{ encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 5000 }
|
||||
);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
logger.debug('CHROMA_MCP', 'No Zscaler certificate found in system keychain', {
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user