{"record":{"id":"8d5f881cf9c0abbe","repo":"tonhowtf/omniget","slug":"tesseract-falhou","errorCode":null,"errorMessage":"tesseract falhou: {}","messagePattern":"tesseract falhou: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":1286,"sourceCode":"    let list = work.join(\"pages.txt\");\n    std::fs::write(\n        &list,\n        pngs.iter()\n            .map(|p| p.to_string_lossy().to_string())\n            .collect::<Vec<_>>()\n            .join(\"\\n\"),\n    )?;\n    let base = work.join(\"ocr\");\n    report(&progress, \"ocr\", 0, Some(pages as u64), Some(langs.clone()));\n    let o = crate::core::process::command(&tesseract)\n        .arg(&list)\n        .arg(&base)\n        .args([\"-l\", &langs, \"--dpi\", &dpi.to_string(), \"pdf\"])\n        .output()\n        .await?;\n    if !o.status.success() {\n        let _ = std::fs::remove_dir_all(&work);\n        return Err(anyhow!(\n            \"tesseract falhou: {}\",\n            String::from_utf8_lossy(&o.stderr).trim()\n        ));\n    }\n    let produced = base.with_extension(\"pdf\");\n    let output = unique(\n        out_dir_for(&input_path, &output_dir).join(format!(\"{} (OCR).pdf\", stem(&input_path))),\n    );\n    if let Some(parent) = output.parent() {\n        std::fs::create_dir_all(parent)?;\n    }\n    if std::fs::rename(&produced, &output).is_err() {\n        std::fs::copy(&produced, &output)?;\n    }\n    let bytes = std::fs::metadata(&output).map(|m| m.len()).unwrap_or(0);\n    let _ = std::fs::remove_dir_all(&work);\n    report(&progress, \"done\", pages as u64, Some(pages as u64), None);\n    Ok(PdfOut {","sourceCodeStart":1268,"sourceCodeEnd":1304,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L1268-L1304","documentation":"This error is raised when an external `tesseract` OCR process exits with a non-zero status while converting images to a searchable PDF. The library captures tesseract's stderr, trims it, and embeds it in the message so the underlying OCR failure reason is visible. Any failure of the spawned tesseract CLI (bad language packs, unreadable images, out-of-memory) surfaces here.","triggerScenarios":"Calling the OCR-to-PDF flow with tesseract installed but the requested `-l` language data missing, corrupted/unsupported input images, invalid `--dpi` values, or the tesseract binary crashing mid-run.","commonSituations":"Missing tesseract language packs (e.g. `por.traineddata` not installed), tesseract not on PATH in CI containers, very large scans exceeding memory, or passing an unsupported language code.","solutions":["Run the same tesseract command manually to see the raw stderr","Install the required tesseract language packs (e.g. `tesseract-ocr-por`)","Verify tesseract is installed and on PATH (`tesseract --version`)","Lower `--dpi` or split large documents into smaller batches","Ensure input images are valid and readable by the process user"],"exampleFix":"// before: fails when language pack missing\n.args([\"-l\", \"por\", \"--dpi\", \"300\", \"pdf\"])\n// after: check available langs first and fall back to eng\nlet langs = if langs_available(\"por\") { \"por\" } else { \"eng\" };\n.args([\"-l\", langs, \"--dpi\", \"300\", \"pdf\"])","handlingStrategy":"try-catch","validationCode":"// Rust: check tesseract availability and language pack before calling\nlet ok = tokio::process::Command::new(\"tesseract\")\n    .args([\"--list-langs\"]).output().await\n    .map(|o| o.status.success()).unwrap_or(false);\nif !ok { return Err(anyhow!(\"tesseract indisponivel\")); }","typeGuard":null,"tryCatchPattern":"match run_ocr_to_pdf(&img, &langs, dpi).await {\n    Ok(pdf) => pdf,\n    Err(e) if e.to_string().contains(\"tesseract falhou\") => {\n        eprintln!(\"OCR falhou: {e}\"); fallback_no_ocr()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Verify tesseract and required language packs are installed at app startup","Pin and document the tesseract version your app was tested with","Validate dpi and language codes before spawning the process","Surface tesseract stderr directly to users instead of a generic message"],"tags":["ocr","external-process","tesseract"],"backgroundTag":"command-not-found","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}