Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions app/src/lib/hooks/useCaptureRecordingSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
CaptureSource,
} from '@/lib/api/types';
import { useAudioRecording } from '@/lib/hooks/useAudioRecording';
import { isShortDictationError } from '@/lib/utils/captureErrors';

/**
* Broadcast to sibling Tauri webviews that the captures list has changed.
Expand Down Expand Up @@ -229,13 +230,11 @@ export function useCaptureRecordingSession(
}
}
},
onError: (err: Error) => {
// Backend's librosa-audioread fallback returns a 400 with this shape
// for tiny/corrupt webm blobs that slip past the client guard —
// translate it to the same friendly message so the user sees one
// consistent cause, not an opaque decode error.
onError: (err: Error, variables) => {
// Keep the brief notice for dictation blobs that slip past the client
// guard, but preserve decode diagnostics for uploaded audio files.
const msg = err.message || '';
if (/could not decode/i.test(msg) || /empty or corrupt/i.test(msg)) {
if (isShortDictationError(msg, variables.source)) {
showError(SHORT_RECORDING_MESSAGE, BRIEF_NOTICE_MS);
} else {
showError(msg || 'Upload failed');
Expand Down
8 changes: 8 additions & 0 deletions app/src/lib/utils/captureErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { CaptureSource } from '@/lib/api/types';

export function isShortDictationError(message: string, source: CaptureSource): boolean {
return (
source === 'dictation' &&
(/could not decode/i.test(message) || /empty or corrupt/i.test(message))
);
}
29 changes: 29 additions & 0 deletions app/tests/captureErrors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, test } from 'bun:test';
import { isShortDictationError } from '../src/lib/utils/captureErrors';

describe('capture upload error classification', () => {
for (const message of ['Could not decode audio', 'Audio is empty or corrupt']) {
test(`preserves file upload error: ${message}`, () => {
expect(isShortDictationError(message, 'file')).toBe(false);
});

test(`preserves recording upload error: ${message}`, () => {
expect(isShortDictationError(message, 'recording')).toBe(false);
});

test(`keeps the existing dictation notice: ${message}`, () => {
expect(isShortDictationError(message, 'dictation')).toBe(true);
});
}

test('matches decode errors case-insensitively', () => {
expect(isShortDictationError('COULD NOT DECODE audio', 'dictation')).toBe(true);
});

test('does not mask unrelated or empty errors', () => {
for (const source of ['file', 'recording', 'dictation'] as const) {
expect(isShortDictationError('Server unavailable', source)).toBe(false);
expect(isShortDictationError('', source)).toBe(false);
}
});
});