fix: resolve Greptile review comments on error handling

- Remove spurious console.error in logger JSON.parse catch (expected control flow)
- Remove debug logging from hot PID cleanup loop (approved override)
- Replace unsafe `error as Error` casts with instanceof checks in ChromaSync, GeminiAgent, OpenRouterAgent
- Wrap non-Error FTS failures with new Error(String()) instead of dropping details

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alex Newman
2026-04-19 20:05:27 -07:00
parent a0dd516cd5
commit 30a0ab4ddb
6 changed files with 7 additions and 13 deletions

View File

@@ -326,11 +326,9 @@ export async function waitForProcessesExit(pids: number[], timeoutMs: number): P
try {
process.kill(pid, 0);
return true;
} catch (error: unknown) {
} catch {
// process.kill(pid, 0) throws when PID doesn't exist — expected during cleanup
if (error instanceof Error) {
logger.debug('SYSTEM', `Process ${pid} no longer exists`, { pid, error: error.message });
}
// [ANTI-PATTERN IGNORED]: Tight loop checking 100s of PIDs every 100ms during cleanup
return false;
}
});

View File

@@ -421,7 +421,7 @@ export class MigrationRunner {
try {
this.createUserPromptsFTS();
} catch (ftsError) {
logger.warn('DB', 'FTS5 not available — user_prompts_fts skipped (search uses ChromaDB)', {}, ftsError instanceof Error ? ftsError : undefined);
logger.warn('DB', 'FTS5 not available — user_prompts_fts skipped (search uses ChromaDB)', {}, ftsError instanceof Error ? ftsError : new Error(String(ftsError)));
}
// Commit transaction

View File

@@ -565,7 +565,7 @@ export class ChromaSync {
try {
await this.runBackfillPipeline(db, backfillProject, existing);
} catch (error) {
logger.error('CHROMA_SYNC', 'Backfill failed', { project: backfillProject }, error as Error);
logger.error('CHROMA_SYNC', 'Backfill failed', { project: backfillProject }, error instanceof Error ? error : new Error(String(error)));
throw new Error(`Backfill failed: ${error instanceof Error ? error.message : String(error)}`);
} finally {
db.close();

View File

@@ -374,7 +374,7 @@ export class GeminiAgent {
return this.fallbackAgent.startSession(session, worker);
}
logger.failure('SDK', 'Gemini agent error', { sessionDbId: session.sessionDbId }, error as Error);
logger.failure('SDK', 'Gemini agent error', { sessionDbId: session.sessionDbId }, error instanceof Error ? error : new Error(String(error)));
throw error;
}

View File

@@ -345,7 +345,7 @@ export class OpenRouterAgent {
return;
}
logger.failure('SDK', 'OpenRouter agent error', { sessionDbId: session.sessionDbId }, error as Error);
logger.failure('SDK', 'OpenRouter agent error', { sessionDbId: session.sessionDbId }, error instanceof Error ? error : new Error(String(error)));
throw error;
}

View File

@@ -154,11 +154,7 @@ class Logger {
try {
input = JSON.parse(toolInput);
} catch (_parseError: unknown) {
// [ANTI-PATTERN IGNORED]: Logger cannot log its own failures, using stderr/console as last resort
// Input is a raw string (e.g., Bash command), use as-is
if (_parseError instanceof Error) {
console.error('[logger] JSON parse failed for tool input:', _parseError);
}
// Input is a raw string (e.g., Bash command), use as-is — JSON.parse failure is expected here
input = toolInput;
}
}