{"record":{"id":"9342c4a6f9d1e3e6","repo":"tonhowtf/omniget","slug":"ghostscript-nao-iniciou","errorCode":null,"errorMessage":"ghostscript nao iniciou: {}","messagePattern":"ghostscript nao iniciou: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf_repair.rs","lineNumber":429,"sourceCode":"\n// ── Orquestração ───────────────────────────────────────────────────────\n\nasync fn open_pages(path: &str) -> Option<usize> {\n    let p = path.to_string();\n    tokio::task::spawn_blocking(move || super::pdf::info(&p, None).ok().map(|i| i.pages))\n        .await\n        .ok()\n        .flatten()\n}\n\nasync fn run_ghostscript(gs: &Path, input: &Path, output: &Path) -> anyhow::Result<()> {\n    let out = crate::core::process::command(gs)\n        .args([\"-q\", \"-dNOPAUSE\", \"-dBATCH\", \"-sDEVICE=pdfwrite\"])\n        .arg(format!(\"-sOutputFile={}\", output.display()))\n        .arg(input)\n        .output()\n        .await\n        .map_err(|e| anyhow!(\"ghostscript nao iniciou: {}\", e))?;\n    if !output.exists() || std::fs::metadata(output).map(|m| m.len()).unwrap_or(0) == 0 {\n        return Err(anyhow!(\n            \"ghostscript não gerou nada: {}\",\n            String::from_utf8_lossy(&out.stderr).trim()\n        ));\n    }\n    Ok(())\n}\n\nfn output_path(opts: &RepairOptions, inp: &Path) -> anyhow::Result<PathBuf> {\n    let dir = if opts.output_dir.trim().is_empty() {\n        inp.parent().map(|p| p.to_path_buf()).unwrap_or_default()\n    } else {\n        PathBuf::from(opts.output_dir.trim())\n    };\n    std::fs::create_dir_all(&dir)?;\n    let stem = inp\n        .file_stem()","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf_repair.rs#L411-L447","documentation":"This error is thrown in run_ghostscript when the tokio async child-process spawn of the Ghostscript executable fails, i.e. `.output()` returns Err before gs even runs. It wraps the underlying io::Error (typically NotFound for a missing binary, or permission/exec issues). It is a pre-execution failure, distinct from Ghostscript running but producing no output.","triggerScenarios":"Calling pdf_repair with mode \"gs\" (or a mode that reaches run_ghostscript) where the path resolved by super::pdf::find_gs() is stale or not executable; the gs binary was uninstalled or moved after detection; PATH lookup fails at spawn time; OS-level exec permission denied.","commonSituations":"Ghostscript not installed; gs installed under a name/path find_gs does not check (e.g. Windows gswin64c vs gs); a broken symlink; antivirus blocking execution; running in a container image without ghostscript package.","solutions":["Install Ghostscript (apt install ghostscript / brew install ghostscript / choco install ghostscript) and ensure it is on PATH","Verify the resolved gs path manually: run `<gs_path> --version`; fix find_gs detection or the PATH if it fails","Check the binary is executable (chmod +x / reinstall); confirm no AV policy blocks spawning it","If you don't need Ghostscript, switch the repair mode to \"rebuild\" which does not use gs"],"exampleFix":"// before\nlet gs = super::pdf::find_gs().await.unwrap(); // panics or passes stale path\n// after\nlet gs = match super::pdf::find_gs().await {\n    Some(p) if std::process::Command::new(&p).arg(\"--version\").output().is_ok() => p,\n    _ => return Err(anyhow!(\"Ghostscript não encontrado ou não executável\")),\n};","handlingStrategy":"fallback","validationCode":"// Rust: check the gs binary is spawnable before requesting mode \"gs\"\nlet ok = match super::pdf::find_gs().await {\n    Some(p) => tokio::process::Command::new(&p).arg(\"--version\").output().await.is_ok(),\n    None => false,\n};\nif !ok { anyhow::bail!(\"Ghostscript indisponível; use mode=\\\"rebuild\\\"\"); }","typeGuard":"fn gs_spawnable(path: &std::path::Path) -> bool {\n    path.is_file() && std::process::Command::new(path).arg(\"--version\").output().map(|o| o.status.success()).unwrap_or(false)\n}","tryCatchPattern":"match run(opts, progress).await {\n    Err(e) if e.to_string().contains(\"ghostscript nao iniciou\") => {\n        // fall back to mode \"rebuild\" (no Ghostscript needed)\n        opts.mode = \"rebuild\".into();\n        run(opts, progress).await\n    }\n    other => other,\n}","preventionTips":["Install Ghostscript in every environment (dev, CI, Docker) where mode \"gs\" may be used","Verify with `gs --version` before shipping pipelines that depend on it","On Windows ensure gswin64c is on PATH, not just the Ghostscript GUI","Prefer mode \"rebuild\" when external dependencies are undesirable"],"tags":["rust","external-process","ghostscript","process-spawn"],"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"}