{"record":{"id":"4221056e3be68840","repo":"tonhowtf/omniget","slug":"ghostscript-falhou","errorCode":null,"errorMessage":"ghostscript falhou: {}","messagePattern":"ghostscript falhou: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":1176,"sourceCode":"                move || {\n                    info(&out.to_string_lossy(), None)\n                        .map(|i| i.pages)\n                        .unwrap_or(0)\n                }\n            })\n            .await\n            .unwrap_or(0);\n            report(&progress, \"done\", 1, Some(1), None);\n            return Ok(CompressResult {\n                output: output.to_string_lossy().to_string(),\n                before,\n                after,\n                method: \"ghostscript\".into(),\n                pages,\n            });\n        }\n        if opts.mode == \"gs\" {\n            return Err(anyhow!(\n                \"ghostscript falhou: {}\",\n                String::from_utf8_lossy(&o.stderr).trim()\n            ));\n        }\n        let _ = std::fs::remove_file(&output);\n    } else if opts.mode == \"gs\" {\n        return Err(anyhow!(\"Ghostscript nao encontrado\"));\n    }\n    let dpi = if opts.dpi == 0 { 110 } else { opts.dpi };\n    let quality = if opts.quality == 0 { 60 } else { opts.quality };\n    let out =\n        tokio::task::spawn_blocking(move || rasterize(&input, &output, dpi, quality, &progress))\n            .await??;\n    Ok(CompressResult {\n        output: out.output,\n        before,\n        after: out.bytes,\n        method: \"raster\".into(),","sourceCodeStart":1158,"sourceCodeEnd":1194,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L1158-L1194","documentation":"In compression mode \"gs\", the tool shells out to the ghostscript binary; if the command ran but exited with failure, it throws \"ghostscript falhou: {stderr}\" including ghostscript's own error output. This indicates ghostscript rejected the arguments or the input PDF.","triggerScenarios":"opts.mode == \"gs\" and the ghostscript process returned a non-zero exit: bad/unsupported gs options, encrypted or corrupt input PDF, unreadable output path, or a ghostscript version lacking the requested device (e.g. pdfwrite).","commonSituations":"Password-protected PDFs; ghostscript installed via minimal package missing pdfwrite; output directory not writable; extremely large PDFs hitting resource limits.","solutions":["Read the stderr fragment in the error — it names the actual gs problem.","Run `gs ... input.pdf` manually with the same args to reproduce and debug.","Remove the password (qpdf --decrypt) if the PDF is encrypted.","Update/reinstall ghostscript if the device (pdfwrite) is missing.","Fall back to another compression mode instead of \"gs\"."],"exampleFix":"// before\ncompress(&CompressOptions { mode: \"gs\".into(), input: encrypted_pdf, .. })\n\n// after\n// decrypt first\nstd::process::Command::new(\"qpdf\").args([\"--decrypt\", \"in.pdf\", \"dec.pdf\"]).status()?;\ncompress(&CompressOptions { mode: \"gs\".into(), input: \"dec.pdf\".into(), .. })","handlingStrategy":"try-catch","validationCode":"let gs = which::which(\"gs\").is_ok();\nlet encrypted = std::fs::read(&opts.input)\n    .map(|d| String::from_utf8_lossy(&d).contains(\"/Encrypt\"))\n    .unwrap_or(false);\nif !gs { return Err(\"ghostscript not installed\"); }\nif encrypted { return Err(\"decrypt the PDF first (qpdf --decrypt)\"); }","typeGuard":null,"tryCatchPattern":"match compress(&opts, &progress).await {\n    Ok(out) => use(out),\n    Err(e) if e.to_string().contains(\"ghostscript falhou\") => {\n        eprintln!(\"gs stderr: {} — run gs manually to debug\", e);\n    }\n    Err(e) => eprintln!(\"compress failed: {e}\"),\n}","preventionTips":["Decrypt password-protected PDFs before gs compression.","Test the exact gs command line manually once in each deployment env.","Pin a known-good ghostscript version in Docker/CI.","Verify the output directory is writable before invoking gs."],"tags":["pdf","ghostscript","external-process","compression","rust"],"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"}