tonhowtf/omniget · error · anyhow

tesseract falhou em

Error message

tesseract falhou em {}: {}

What it means

`ocr::run` invokes the located tesseract binary with `input stdout -l <langs> --psm 3`; if the process exits with a non-zero status, the error wraps tesseract's own stderr. This means tesseract ran but failed on this specific input or language set.

Solutions

  1. Read the embedded stderr in the message: if it says 'Failed to find requested language data', install the language pack (e.g. `brew install tesseract-lang`, `apt install tesseract-ocr-<lang>`) or pass an installed language code from `--list-langs`.
  2. Validate the input is an existing image file tesseract supports (PNG/JPEG/TIFF/BMP) before calling run().
  3. Run `tesseract <input> stdout -l <langs>` manually to reproduce and see the full stderr.

Example fix

// before
let text = ocr::run(&[pdf_path], "por", progress).await?;
// after
let langs = ocr::status().await.languages;
let lang = if langs.contains("por") { "por" } else { "eng" };
let text = ocr::run(&[img_path], lang, progress).await?;
Defensive patterns

Strategy: validation

Validate before calling

let st = ocr::status().await;
let langs = st.languages;
assert!(langs.contains(&"por".to_string()), "idioma nao instalado; disponiveis: {langs:?}");
assert!(inputs.iter().all(|p| std::path::Path::new(p).is_file()), "arquivo de entrada inexistente");

Try / catch

match ocr::run(&inputs, langs, progress).await {
    Ok(r) => r,
    Err(e) if e.to_string().contains("falhou em") => {
        // stderr is embedded after the input path; log and continue with next file
        eprintln!("OCR skip: {e}");
        Vec::new()
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Any `run` call (or share_file/share_url/share_text/ping/refresh path) where tesseract exits non-zero: input file is not a readable image, image format unsupported/corrupt, or a requested language code (e.g. `por`) has no traineddata installed.

Common situations: Requesting a language not installed (missing tesseract-lang / tesseract-ocr-por package); passing PDFs or SVGs that tesseract cannot open; passing paths with characters the shell-layer mishandles; corrupt or zero-byte image files.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/5ec0e0232525f463. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/ocr.rs:124

    };
    let mut out = Vec::new();
    let total = inputs.len() as u64;
    for (i, input) in inputs.iter().enumerate() {
        super::report(
            &progress,
            "ocr",
            "progress",
            i as u64,
            Some(total),
            Some(input.clone()),
        );
        let o = crate::core::process::command(&bin)
            .arg(input)
            .args(["stdout", "-l", langs, "--psm", "3"])
            .output()
            .await?;
        if !o.status.success() {
            return Err(anyhow!(
                "tesseract falhou em {}: {}",
                input,
                String::from_utf8_lossy(&o.stderr).trim()
            ));
        }
        out.push(OcrResult {
            path: input.clone(),
            text: String::from_utf8_lossy(&o.stdout).trim().to_string(),
        });
    }
    super::report(&progress, "ocr", "done", total, Some(total), None);
    Ok(out)
}

View on GitHub (pinned to 8600b91f42)