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:
@@ -439,47 +439,50 @@ export async function updateFolderClaudeMdFiles(
|
||||
|
||||
// Process each folder
|
||||
for (const folderPath of folderPaths) {
|
||||
let response: Response;
|
||||
try {
|
||||
// Fetch timeline via existing API (uses socket or TCP automatically)
|
||||
const response = await workerHttpRequest(
|
||||
response = await workerHttpRequest(
|
||||
`/api/search/by-file?filePath=${encodeURIComponent(folderPath)}&limit=${limit}&project=${encodeURIComponent(project)}&isFolder=true`
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
logger.error('FOLDER_INDEX', 'Failed to fetch timeline', { folderPath, status: response.status });
|
||||
continue;
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
if (!result.content?.[0]?.text) {
|
||||
logger.debug('FOLDER_INDEX', 'No content for folder', { folderPath });
|
||||
continue;
|
||||
}
|
||||
|
||||
const formatted = formatTimelineForClaudeMd(result.content[0].text);
|
||||
|
||||
// Fix for #794: Don't create new context files if there's no activity
|
||||
// But update existing ones to show "No recent activity" if they already exist
|
||||
const claudeMdPath = path.join(folderPath, targetFilename);
|
||||
const hasNoActivity = formatted.includes('*No recent activity*');
|
||||
const fileExists = existsSync(claudeMdPath);
|
||||
|
||||
if (hasNoActivity && !fileExists) {
|
||||
logger.debug('FOLDER_INDEX', 'Skipping empty context file creation', { folderPath, targetFilename });
|
||||
continue;
|
||||
}
|
||||
|
||||
writeClaudeMdToFolder(folderPath, formatted, targetFilename);
|
||||
|
||||
logger.debug('FOLDER_INDEX', 'Updated context file', { folderPath, targetFilename });
|
||||
} catch (error) {
|
||||
} catch (error: unknown) {
|
||||
// Fire-and-forget: log warning but don't fail
|
||||
const err = error as Error;
|
||||
logger.error('FOLDER_INDEX', `Failed to update ${targetFilename}`, {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const stack = error instanceof Error ? error.stack : undefined;
|
||||
logger.error('FOLDER_INDEX', `Failed to fetch timeline for ${targetFilename}`, {
|
||||
folderPath,
|
||||
errorMessage: err.message,
|
||||
errorStack: err.stack
|
||||
errorMessage: message,
|
||||
errorStack: stack
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
logger.error('FOLDER_INDEX', 'Failed to fetch timeline', { folderPath, status: response.status });
|
||||
continue;
|
||||
}
|
||||
|
||||
const result = await response.json() as { content?: Array<{ text?: string }> };
|
||||
if (!result.content?.[0]?.text) {
|
||||
logger.debug('FOLDER_INDEX', 'No content for folder', { folderPath });
|
||||
continue;
|
||||
}
|
||||
|
||||
const formatted = formatTimelineForClaudeMd(result.content[0].text);
|
||||
|
||||
// Fix for #794: Don't create new context files if there's no activity
|
||||
// But update existing ones to show "No recent activity" if they already exist
|
||||
const claudeMdPath = path.join(folderPath, targetFilename);
|
||||
const hasNoActivity = formatted.includes('*No recent activity*');
|
||||
const fileExists = existsSync(claudeMdPath);
|
||||
|
||||
if (hasNoActivity && !fileExists) {
|
||||
logger.debug('FOLDER_INDEX', 'Skipping empty context file creation', { folderPath, targetFilename });
|
||||
continue;
|
||||
}
|
||||
|
||||
writeClaudeMdToFolder(folderPath, formatted, targetFilename);
|
||||
|
||||
logger.debug('FOLDER_INDEX', 'Updated context file', { folderPath, targetFilename });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user