Skip to content

Commit bc14124

Browse files
liangweifengclaude
andcommitted
fix: save error history when pipeline throws exception
The catch block in stopRecording only set error state but didn't save a history item. When runPipeline itself threw (network failure, JSON parse error), the recording was lost — no history entry, and the saved audio file became orphaned. Fix: hoist audioPath above try block so it's accessible in catch, then save an error HistoryItem (matching the result.success===false path). Users now see all failed recordings in History, and audio files are properly tracked for cleanup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 13dc60b commit bc14124

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/hooks/useRecorder.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,9 @@ export function useRecorder() {
160160
if (configRef.current.soundEnabled) playBeep(520, 0.15);
161161
setState((s) => ({ ...s, status: 'processing', audioLevel: 0 }));
162162

163+
let audioPath: string | undefined;
163164
try {
164165
const audioBuffer = await recorder.stop();
165-
166-
// Save audio to file (not inline base64 — keeps config.json small)
167-
let audioPath: string | undefined;
168166
if (window.electronAPI) {
169167
try {
170168
const audioBytes = new Uint8Array(audioBuffer);
@@ -337,7 +335,20 @@ export function useRecorder() {
337335
}
338336
} catch (e) {
339337
if (generationRef.current !== gen) return;
340-
setState((s) => ({ ...s, status: 'idle', error: errMsg(e) }));
338+
const errorMsg = errMsg(e);
339+
setState((s) => ({ ...s, status: 'idle', error: errorMsg }));
340+
// Save error to history (matches the result.success===false path)
341+
const errorItem: HistoryItem = {
342+
id: Date.now().toString(36) + Math.random().toString(36).slice(2, 6),
343+
timestamp: Date.now(),
344+
rawText: '',
345+
processedText: '',
346+
durationMs,
347+
wordCount: 0,
348+
audioPath,
349+
error: errorMsg,
350+
};
351+
addHistoryItem(errorItem);
341352
}
342353
}, [addHistoryItem]);
343354

0 commit comments

Comments
 (0)