fix(hooks): replace empty catch blocks with debug logging in transcript

This commit is contained in:
YeonGyu-Kim
2026-04-04 02:37:53 +09:00
parent 6acca09bd0
commit cab84518de
+27 -9
View File
@@ -4,7 +4,7 @@ import { tmpdir } from "os"
import { randomUUID } from "crypto" import { randomUUID } from "crypto"
import type { TranscriptEntry } from "./types" import type { TranscriptEntry } from "./types"
import { transformToolName } from "../../shared/tool-name" import { transformToolName } from "../../shared/tool-name"
import { getClaudeConfigDir } from "../../shared" import { getClaudeConfigDir, log } from "../../shared"
const TRANSCRIPT_DIR = join(getClaudeConfigDir(), "transcripts") const TRANSCRIPT_DIR = join(getClaudeConfigDir(), "transcripts")
@@ -74,13 +74,21 @@ export function clearTranscriptCache(sessionId?: string): void {
if (sessionId) { if (sessionId) {
const entry = transcriptCache.get(sessionId) const entry = transcriptCache.get(sessionId)
if (entry?.tempPath) { if (entry?.tempPath) {
try { unlinkSync(entry.tempPath) } catch { /* ignore */ } try {
unlinkSync(entry.tempPath)
} catch (error) {
log("[transcript] failed to clean up cached temp transcript", { error })
}
} }
transcriptCache.delete(sessionId) transcriptCache.delete(sessionId)
} else { } else {
for (const [, entry] of transcriptCache) { for (const [, entry] of transcriptCache) {
if (entry.tempPath) { if (entry.tempPath) {
try { unlinkSync(entry.tempPath) } catch { /* ignore */ } try {
unlinkSync(entry.tempPath)
} catch (error) {
log("[transcript] failed to clean up cached temp transcript", { error })
}
} }
} }
transcriptCache.clear() transcriptCache.clear()
@@ -176,7 +184,11 @@ export async function buildTranscriptFromSession(
: [] : []
if (cached?.tempPath) { if (cached?.tempPath) {
try { unlinkSync(cached.tempPath) } catch { /* ignore */ } try {
unlinkSync(cached.tempPath)
} catch (error) {
log("[transcript] failed to clean up stale temp transcript", { error })
}
} }
transcriptCache.set(sessionId, { transcriptCache.set(sessionId, {
@@ -189,7 +201,11 @@ export async function buildTranscriptFromSession(
const allEntries = [...baseEntries, buildCurrentEntry(currentToolName, currentToolInput)] const allEntries = [...baseEntries, buildCurrentEntry(currentToolName, currentToolInput)]
if (previousTempPath) { if (previousTempPath) {
try { unlinkSync(previousTempPath) } catch { /* ignore */ } try {
unlinkSync(previousTempPath)
} catch (error) {
log("[transcript] failed to clean up previous temp transcript", { error })
}
} }
const tempPath = join( const tempPath = join(
@@ -206,7 +222,8 @@ export async function buildTranscriptFromSession(
} }
return tempPath return tempPath
} catch { } catch (error) {
log("[transcript] failed to build transcript from session", { error })
try { try {
const tempPath = join( const tempPath = join(
tmpdir(), tmpdir(),
@@ -214,7 +231,8 @@ export async function buildTranscriptFromSession(
) )
writeFileSync(tempPath, buildCurrentEntry(currentToolName, currentToolInput) + "\n") writeFileSync(tempPath, buildCurrentEntry(currentToolName, currentToolInput) + "\n")
return tempPath return tempPath
} catch { } catch (fallbackError) {
log("[transcript] failed to write fallback transcript", { error: fallbackError })
return null return null
} }
} }
@@ -224,7 +242,7 @@ export function deleteTempTranscript(path: string | null): void {
if (!path) return if (!path) return
try { try {
unlinkSync(path) unlinkSync(path)
} catch { } catch (error) {
// Ignore deletion errors log("[transcript] failed to delete temp transcript", { error })
} }
} }