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:
@@ -38,8 +38,11 @@ export function detectWorktree(cwd: string): WorktreeInfo {
|
||||
let stat;
|
||||
try {
|
||||
stat = statSync(gitPath);
|
||||
} catch {
|
||||
// No .git at all - not a git repo
|
||||
} catch (error: unknown) {
|
||||
// No .git at all - not a git repo (ENOENT is expected, other errors are noteworthy)
|
||||
if (error instanceof Error && (error as NodeJS.ErrnoException).code !== 'ENOENT') {
|
||||
console.warn(`[worktree] Unexpected error checking .git:`, error);
|
||||
}
|
||||
return NOT_A_WORKTREE;
|
||||
}
|
||||
|
||||
@@ -52,7 +55,8 @@ export function detectWorktree(cwd: string): WorktreeInfo {
|
||||
let content: string;
|
||||
try {
|
||||
content = readFileSync(gitPath, 'utf-8').trim();
|
||||
} catch {
|
||||
} catch (error: unknown) {
|
||||
console.warn(`[worktree] Failed to read .git file:`, error instanceof Error ? error.message : String(error));
|
||||
return NOT_A_WORKTREE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user