tonhowtf/omniget · error
subtitle_grammar_fix error surfaced to user via err()…
Error message
subtitle_grammar_fix error surfaced to user via err() (localized toast)
What it means
grammarFix failed while invoking subtitle_grammar_fix to apply AI grammar correction to the cues with the chosen style; err() surfaces the error as a localized toast and cues are left unchanged. Backend 'ai_not_configured' is mapped to the not-configured message by err().
Solutions
- If the toast indicates not-configured, set up the AI provider/key in backend configuration.
- Confirm grammarStyle matches one of the backend's supported style values.
- Check upstream AI service health/limits if the error points at the request itself.
- Retry after transient failures; consider chunking large cue lists.
Example fix
// before
await invoke("subtitle_grammar_fix", { cues, style: grammarStyle });
// after
if (!aiConfigured()) { showToast("error", $t("downloads.sw.not_configured")); return; }
await invoke("subtitle_grammar_fix", { cues, style: grammarStyle }); Defensive patterns
Strategy: validation
Validate before calling
if (!(await invoke<boolean>("ai_configured").catch(() => false))) { err("ai_not_configured"); return; }
const styles = await invoke<string[]>("grammar_styles").catch(() => []);
if (!styles.includes(grammarStyle)) { showToast("error", $t("downloads.sw.invalid_style")); return; } Type guard
function isSupportedStyle(v: unknown, allowed: readonly string[]): v is string {
return typeof v === "string" && allowed.includes(v);
} Try / catch
try {
cues = await invoke<Cue[]>("subtitle_grammar_fix", { cues, style: grammarStyle });
showToast("success", $t("downloads.sw.grammar_done") as string);
} catch (e) {
err(e); // localized toast
} finally {
busy = false;
} Prevention
- Gate grammar-fix UI on AI configuration status fetched at startup.
- Derive grammarStyle options from the backend's supported list rather than hardcoding.
- Add retry/backoff for transient AI provider failures.
- Chunk long cue lists so a single oversized request can't fail the whole pass.
When it happens
Trigger: invoke('subtitle_grammar_fix',{cues,style:grammarStyle}) rejecting — AI provider unconfigured (ai_not_configured), unsupported grammar style value, upstream AI API failure, or invalid cues payload.
Common situations: Missing AI configuration/key on the backend; selecting a grammar style the backend doesn't recognize; AI service outage/quota limits; very long subtitle files timing out the AI request.
Understand the failure class
Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.
Related errors
- subtitle_translate error surfaced to user via err()…
- $t('common.error') | mapped: ai_not_configured ->…
- subtitle_load error surfaced to user via err() (localized…
- waveform_peaks/detect_shot_changes error surfaced to user…
- escolha a pasta de destino para organizar
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/ed7359d4a523ac39.
Report an issue: GitHub.
Appendix: source
Thrown at src/components/downloads/SubtitleWorkshop.svelte:179
showToast("success", $t("downloads.sw.translated") as string);
} catch (e) {
err(e);
} finally {
busy = false;
}
}
async function grammarFix() {
if (!cues.length || busy) return;
busy = true;
try {
cues = await invoke<Cue[]>("subtitle_grammar_fix", {
cues,
style: grammarStyle,
});
showToast("success", $t("downloads.sw.grammar_done") as string);
} catch (e) {
err(e);
} finally {
busy = false;
}
}
function autoFix() {
if (!cues.length) return;
const MIN_MS = 700;
const MAX_LINE = 42;
let changes = 0;
let next = cues
.filter((c) => c.text.trim().length > 0)
.map((c) => ({ ...c, text: c.text.trim() }))
.sort((a, b) => a.start_ms - b.start_ms);
if (next.length !== cues.length) changes += cues.length - next.length;
for (let i = 0; i < next.length; i++) {View on GitHub (pinned to 8600b91f42)