{"record":{"id":"726c60d68e860b62","repo":"tonhowtf/omniget","slug":"n-o-abri-o-pdf-redact","errorCode":null,"errorMessage":"não abri o PDF: {}","messagePattern":"não abri o PDF: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf_redact.rs","lineNumber":520,"sourceCode":"        .file_stem()\n        .map(|s| s.to_string_lossy().to_string())\n        .unwrap_or_else(|| \"documento\".into());\n    let suffix = if opts.suffix.trim().is_empty() {\n        \"-tarjado\"\n    } else {\n        opts.suffix.trim()\n    };\n    Ok(dir.join(format!(\"{}{}.pdf\", stem, suffix)))\n}\n\nfn load(input: &str, password: &str) -> anyhow::Result<Document> {\n    let doc = if password.is_empty() {\n        Document::load(input)\n    } else {\n        let bytes = std::fs::read(input)?;\n        Document::load_mem_with_options(&bytes, lopdf::LoadOptions::with_password(password))\n    };\n    doc.map_err(|e| anyhow!(\"não abri o PDF: {}\", e))\n}\n\n/// Fontes da página que usam código de 2 bytes (Type0/Identity).\nfn two_byte_fonts(doc: &Document, page_id: lopdf::ObjectId) -> Vec<String> {\n    let mut out = Vec::new();\n    let Ok((_, res_ids)) = doc.get_page_resources(page_id) else {\n        return out;\n    };\n    let mut dicts: Vec<lopdf::Dictionary> = Vec::new();\n    if let Ok(page) = doc.get_dictionary(page_id) {\n        if let Ok(r) = page.get(b\"Resources\") {\n            if let Ok(d) = r.as_dict() {\n                dicts.push(d.clone());\n            }\n        }\n    }\n    for id in res_ids {\n        if let Ok(d) = doc.get_dictionary(id) {","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf_redact.rs#L502-L538","documentation":"In pdf_redact's load(), opening the input PDF failed. The lopdf error from Document::load / Document::load_mem_with_options is wrapped with 'não abri o PDF: {}'. For password-protected files it reads bytes and loads with LoadOptions::with_password.","triggerScenarios":"Input path does not exist or is unreadable; the file is not a valid PDF (corrupt/truncated); an encrypted PDF was loaded with a missing or wrong password.","commonSituations":"User picked a locked PDF without entering the password; wrong password supplied; file moved/deleted between selection and processing; .docx or other non-PDF passed in.","solutions":["Verify the path exists and is a valid PDF before calling run","Supply the correct user/owner password in opts.password for encrypted PDFs","Open the file outside the closure to distinguish not-found from parse errors","Check the wrapped lopdf error detail for the exact cause"],"exampleFix":"// before\nlet pw = if opts.password.is_empty() { None } else { Some(opts.password.as_str()) };\nlet doc = load(&opts.input, pw)?;\n// after\nif !std::path::Path::new(&opts.input).exists() { bail!(\"file not found: {}\", opts.input); }\nlet doc = load(&opts.input, pw).map_err(|e| e.context(\"wrong password or corrupt PDF\"))?;","handlingStrategy":"validation","validationCode":"let p = std::path::Path::new(input);\nif !p.exists() { bail!(\"file not found: {}\", input); }\nlet head = std::fs::read(p)?.get(..5).map(|b| b == b\"%PDF-\").unwrap_or(false);\nif !head { bail!(\"not a PDF\"); }","typeGuard":"fn is_loadable(path: &str, pw: &str) -> bool {\n    match if pw.is_empty() { lopdf::Document::load(path) } else {\n        lopdf::Document::load_mem_with_options(&std::fs::read(path).unwrap_or_default(), lopdf::LoadOptions::with_password(pw))\n    } { Ok(_) => true, Err(_) => false }\n}","tryCatchPattern":"match load(input, pw) {\n    Err(e) if e.to_string().contains(\"não abri o PDF\") => Err(anyhow!(\"wrong password or corrupt PDF: {}\", e)),\n    r => r,\n}","preventionTips":["Prompt for a password when the PDF reports encryption","Validate the %PDF- header before processing","Check the file still exists after UI selection"],"tags":["pdf","lopdf","file-open","password"],"backgroundTag":"file-open-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}