SubtitleEdit/subtitleedit · error · Exception
{error}
Error message
{error} What it means
Thrown inside RunLlmOcr as a fail-fast guard: on the FIRST group only, if the OCR call returned empty text AND the engine's getError() is non-empty, the scan aborts immediately instead of grinding through every frame and reporting 'no subtitles found'. This catches a globally-broken engine early — most commonly a wrong API key or URL for the GLM/Ollama/LlamaCpp backends.
Source
Thrown at src/ui/Features/Video/VideoOcr/VideoOcrViewModel.cs:1053
Func<VideoOcrFrameGroup, Task<string>> ocr,
Func<string> getError,
Action reportProgress,
Action<VideoOcrFrameGroup> addPreviewLine,
CancellationToken cancellationToken)
{
var isFirst = true;
foreach (var group in ocrGroups)
{
cancellationToken.ThrowIfCancellationRequested();
group.Text = VideoOcrLineBuilder.CleanOcrResult(await ocr(group));
// Fail fast on a broken engine (wrong API key/URL) instead of grinding
// through the whole video and reporting "no subtitles found".
var error = getError();
if (isFirst && string.IsNullOrEmpty(group.Text) && !string.IsNullOrEmpty(error))
{
throw new Exception(error);
}
isFirst = false;
reportProgress();
addPreviewLine(group);
}
}
private async Task<bool> EnsureEngineIsAvailable()
{
var engineType = SelectedEngine.EngineType;
if (engineType == OcrEngineType.Glm && string.IsNullOrWhiteSpace(GlmApiKey))
{
await MessageBox.Show(
Window!,
Se.Language.General.Error,
"An API key is required for the GLM API engine.",View on GitHub (pinned to 17a9f07487)
Solutions
- Read the engine.Error text in the exception — it is the backend's own error (auth/model/HTTP).
- For GLM: verify the API key is set and valid in settings.
- For Ollama/LlamaCpp: confirm the URL is reachable and the named model is loaded (curl the /api/tags or /v1/models endpoint).
- Correct the URL/model/key and re-run; only after the first frame succeeds will the rest proceed.
Example fix
// before
var error = getError();
if (isFirst && string.IsNullOrEmpty(group.Text) && !string.IsNullOrEmpty(error))
throw new Exception(error);
// after - name the engine and frame so the user knows where it died
var error = getError();
if (isFirst && string.IsNullOrEmpty(group.Text) && !string.IsNullOrEmpty(error))
throw new Exception($"OCR engine error on first frame ({group.RepresentativeFileName}): " + error); Defensive patterns
Strategy: validation
Validate before calling
// Validate credentials/endpoint before the scan for each LLM backend.
if (engineType == OcrEngineType.Glm && string.IsNullOrWhiteSpace(GlmApiKey)) throw new Exception("GLM API key is required.");
if (engineType == OcrEngineType.Ollama && !await IsReachable(OllamaUrl)) throw new Exception("Ollama server is not reachable."); Try / catch
try { await RunLlmOcr(...); }
catch (Exception ex) // fail-fast guard re-throws the engine error
{
SeLogger.Error(ex, "LLM OCR failed on first frame - check API key/URL/model");
await MessageBox.Show(Window!, Se.Language.General.Error, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
} Prevention
- Verify the API key/URL/model before starting the scan.
- For Ollama/LlamaCpp, confirm the named model is loaded.
- Treat a first-frame empty+error as an auth/config problem, not empty content.
When it happens
Trigger: First frame yields no text and the engine reported an error: invalid/missing API key (GLM), wrong base URL, model name not found on the server, network/auth failure, or the inference server returning an error status.
Common situations: GLM API key empty or revoked; Ollama/LlamaCpp URL wrong or server not running; model id typo; rate-limit/auth error from the provider; server started but model failed to load.
Related errors
- API key invalid (or perhaps billing/API is not enabled)?
- llama.cpp returned {(int)resp.StatusCode}: {json}
- Ollama returned {(int)resp.StatusCode}: {json}
- API key invalid (or perhaps billing/API is not enabled)?
- Error calling Cloud Vision API: {httpException.Message}
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/0ba435757f399ce7.
Report an issue: GitHub.