{"record":{"id":"d3b8c5b798f30086","repo":"tonhowtf/omniget","slug":"n-o-abri-o-pdf","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_form.rs","lineNumber":308,"sourceCode":"        kind,\n        value,\n        options,\n        page,\n        rect,\n        readonly: ff & FF_READONLY != 0,\n        required: ff & FF_REQUIRED != 0,\n        multiline: ff & FF_MULTILINE != 0,\n    });\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/// Lista os campos do formulário.\npub fn read_fields(input: &str, password: &str) -> anyhow::Result<Vec<Field>> {\n    let doc = load(input, password)?;\n    Ok(fields_of(&doc))\n}\n\nfn fields_of(doc: &Document) -> Vec<Field> {\n    let Some(form) = acroform(doc) else {\n        return Vec::new();\n    };\n    let pages = page_index(doc);\n    let roots: Vec<ObjectId> = form\n        .get(b\"Fields\")\n        .and_then(Object::as_array)\n        .map(|a| a.iter().filter_map(as_ref).collect())\n        .unwrap_or_default();","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf_form.rs#L290-L326","documentation":"This error wraps any failure from the lopdf Document::load / load_mem_with_options call when opening the input PDF in pdf_form.rs, producing a single user-facing message 'não abri o PDF: {inner}'. It is raised by the private load helper, which chooses memory-load with a password when one is given, or plain load otherwise.","triggerScenarios":"Calling read_fields or fill with a path that does not exist, is a directory, or is unreadable; the file is not a valid PDF (corrupt download, wrong extension); the file is encrypted and either no password was supplied (empty password → plain Document::load fails) or the supplied password is wrong; unsupported PDF features cause lopdf to reject the file.","commonSituations":"User picks a moved/renamed/deleted file; encrypted PDF from a bank/government portal with a password the app wasn't given; passwords with encoding mismatches (e.g. non-ASCII handled differently by the source app); file truncated mid-upload; path containing whitespace not trimmed.","solutions":["Verify the input path exists and is a readable regular file before calling read_fields/fill","If the PDF is encrypted, pass the correct password so load_mem_with_options is used; empty password forces an unencrypted load attempt","Open the PDF in a viewer to confirm it is valid and not corrupt; re-obtain the file if damaged","Inspect the inner error in the message ('não abri o PDF: ...') to distinguish io::Error (path) vs lopdf parse/decrypt errors and fix accordingly"],"exampleFix":"// before\nread_fields(\"/tmp/missing.pdf\", \"\")?; // não abri o PDF: No such file or directory\n// after\nlet path = Path::new(input);\nanyhow::ensure!(path.is_file(), \"arquivo não encontrado: {}\", input);\nread_fields(input, &password)?;","handlingStrategy":"validation","validationCode":"let path = Path::new(input);\nanyhow::ensure!(path.is_file(), \"not a file: {}\", input);\n// optionally probe encryption first:\n// if pdf_is_encrypted(input) && password.is_empty() { prompt for password }","typeGuard":"fn readable_pdf(path: &str) -> bool {\n    std::fs::File::open(path).map(|mut f| {\n        let mut m = [0u8; 5];\n        std::io::Read::read_exact(&mut f, &mut m).is_ok() && &m == b\"%PDF-\"\n    }).unwrap_or(false)\n}","tryCatchPattern":"match read_fields(input, password) {\n    Err(e) if e.to_string().starts_with(\"não abri o PDF\") => {\n        eprintln!(\"could not open PDF (check path/encryption): {e}\");\n    }\n    Ok(fields) => { /* use fields */ }\n    Err(e) => return Err(e),\n}","preventionTips":["Check the path exists and is a regular file before calling","Supply the password for encrypted PDFs; empty password only works on unencrypted files","Validate the file starts with %PDF- to catch corrupt/misnamed files","Keep paths trimmed and as-is from the file picker to avoid whitespace/encoding surprises"],"tags":["pdf","file-open","lopdf"],"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"}