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:
Alex Newman
2026-04-19 19:57:00 -07:00
parent c9adb1c77b
commit a0dd516cd5
91 changed files with 4846 additions and 3414 deletions
@@ -63,82 +63,19 @@ export class ChromaSearchStrategy extends BaseSearchStrategy implements SearchSt
let sessions: SessionSummarySearchResult[] = [];
let prompts: UserPromptSearchResult[] = [];
// Build Chroma where filter for doc_type and project
const whereFilter = this.buildWhereFilter(searchType, project);
logger.debug('SEARCH', 'ChromaSearchStrategy: Querying Chroma', { query, searchType });
try {
// Build Chroma where filter for doc_type and project
const whereFilter = this.buildWhereFilter(searchType, project);
// Step 1: Chroma semantic search
logger.debug('SEARCH', 'ChromaSearchStrategy: Querying Chroma', { query, searchType });
const chromaResults = await this.chromaSync.queryChroma(
query,
SEARCH_CONSTANTS.CHROMA_BATCH_SIZE,
whereFilter
);
logger.debug('SEARCH', 'ChromaSearchStrategy: Chroma returned matches', {
matchCount: chromaResults.ids.length
return await this.executeChromaSearch(query, whereFilter, {
searchObservations, searchSessions, searchPrompts,
obsType, concepts, files, orderBy, limit, project
});
if (chromaResults.ids.length === 0) {
// No matches - this is the correct answer
return {
results: { observations: [], sessions: [], prompts: [] },
usedChroma: true,
fellBack: false,
strategy: 'chroma'
};
}
// Step 2: Filter by recency (90 days)
const recentItems = this.filterByRecency(chromaResults);
logger.debug('SEARCH', 'ChromaSearchStrategy: Filtered by recency', {
count: recentItems.length
});
// Step 3: Categorize by document type
const categorized = this.categorizeByDocType(recentItems, {
searchObservations,
searchSessions,
searchPrompts
});
// Step 4: Hydrate from SQLite with additional filters
if (categorized.obsIds.length > 0) {
const obsOptions = { type: obsType, concepts, files, orderBy, limit, project };
observations = this.sessionStore.getObservationsByIds(categorized.obsIds, obsOptions);
}
if (categorized.sessionIds.length > 0) {
sessions = this.sessionStore.getSessionSummariesByIds(categorized.sessionIds, {
orderBy,
limit,
project
});
}
if (categorized.promptIds.length > 0) {
prompts = this.sessionStore.getUserPromptsByIds(categorized.promptIds, {
orderBy,
limit,
project
});
}
logger.debug('SEARCH', 'ChromaSearchStrategy: Hydrated results', {
observations: observations.length,
sessions: sessions.length,
prompts: prompts.length
});
return {
results: { observations, sessions, prompts },
usedChroma: true,
fellBack: false,
strategy: 'chroma'
};
} catch (error) {
logger.error('SEARCH', 'ChromaSearchStrategy: Search failed', {}, error as Error);
const errorObj = error instanceof Error ? error : new Error(String(error));
logger.error('WORKER', 'ChromaSearchStrategy: Search failed', {}, errorObj);
// Return empty result - caller may try fallback strategy
return {
results: { observations: [], sessions: [], prompts: [] },
@@ -149,6 +86,68 @@ export class ChromaSearchStrategy extends BaseSearchStrategy implements SearchSt
}
}
private async executeChromaSearch(
query: string,
whereFilter: Record<string, any> | undefined,
options: {
searchObservations: boolean;
searchSessions: boolean;
searchPrompts: boolean;
obsType?: string | string[];
concepts?: string | string[];
files?: string | string[];
orderBy: 'relevance' | 'date_desc' | 'date_asc';
limit: number;
project?: string;
}
): Promise<StrategySearchResult> {
const chromaResults = await this.chromaSync.queryChroma(
query,
SEARCH_CONSTANTS.CHROMA_BATCH_SIZE,
whereFilter
);
if (chromaResults.ids.length === 0) {
return {
results: { observations: [], sessions: [], prompts: [] },
usedChroma: true,
fellBack: false,
strategy: 'chroma'
};
}
const recentItems = this.filterByRecency(chromaResults);
const categorized = this.categorizeByDocType(recentItems, options);
let observations: ObservationSearchResult[] = [];
let sessions: SessionSummarySearchResult[] = [];
let prompts: UserPromptSearchResult[] = [];
if (categorized.obsIds.length > 0) {
const obsOptions = { type: options.obsType, concepts: options.concepts, files: options.files, orderBy: options.orderBy, limit: options.limit, project: options.project };
observations = this.sessionStore.getObservationsByIds(categorized.obsIds, obsOptions);
}
if (categorized.sessionIds.length > 0) {
sessions = this.sessionStore.getSessionSummariesByIds(categorized.sessionIds, {
orderBy: options.orderBy, limit: options.limit, project: options.project
});
}
if (categorized.promptIds.length > 0) {
prompts = this.sessionStore.getUserPromptsByIds(categorized.promptIds, {
orderBy: options.orderBy, limit: options.limit, project: options.project
});
}
return {
results: { observations, sessions, prompts },
usedChroma: true,
fellBack: false,
strategy: 'chroma'
};
}
/**
* Build Chroma where filter for document type and project
*