{"record":{"id":"22a46c2f622e676e","repo":"tonhowtf/omniget","slug":"nao-leu","errorCode":null,"errorMessage":"nao leu {}: {}","messagePattern":"nao leu (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":188,"sourceCode":"    let leaked: &'static Api = Box::leak(Box::new(api));\n    *guard = Some(leaked);\n    Ok(leaked)\n}\n\npub fn available() -> bool {\n    crate::core::pdfium::is_installed()\n}\n\nstruct Document {\n    api: &'static Api,\n    doc: Doc,\n    // O PDFium lê da memória enquanto o documento estiver aberto.\n    _data: Vec<u8>,\n}\n\nimpl Document {\n    fn open(api: &'static Api, path: &Path, password: Option<&str>) -> anyhow::Result<Self> {\n        let data = std::fs::read(path).map_err(|e| anyhow!(\"nao leu {}: {}\", path.display(), e))?;\n        let pw = CString::new(password.unwrap_or(\"\")).unwrap_or_default();\n        let doc =\n            unsafe { (api.load_mem)(data.as_ptr() as *const c_void, data.len(), pw.as_ptr()) };\n        if doc.is_null() {\n            let code = unsafe { (api.last_error)() };\n            let why = match code {\n                2 => \"arquivo nao encontrado ou ilegivel\",\n                3 => \"nao e um PDF valido\",\n                4 => \"senha incorreta ou ausente\",\n                5 => \"esquema de seguranca nao suportado\",\n                6 => \"pagina invalida\",\n                _ => \"erro desconhecido\",\n            };\n            return Err(anyhow!(\"{}: {}\", path.display(), why));\n        }\n        Ok(Document {\n            api,\n            doc,","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L170-L206","documentation":"Document::open wraps std::fs::read failure with this message naming the PDF path and the io::Error. Before PDFium even sees the file, the whole PDF must be read into memory (PDFium reads from the buffer while the document is open), so any I/O failure aborts here. The inner error distinguishes NotFound, PermissionDenied, IsADirectory, etc.","triggerScenarios":"Calling any PDF operation with a path that does not exist, is unreadable (permissions), is a directory, or on a file that disappears/is locked mid-operation.","commonSituations":"User moved/renamed/deleted the PDF after picking it in a file dialog; opening files on a disconnected network drive or ejected USB; permission issues after the app gained file access only via a dialog; passing a folder path instead of a file.","solutions":["Verify the path exists and is a regular file before opening (Path::is_file)","Check file read permissions and request access (macOS sandbox: security-scoped bookmark)","Re-prompt the user to re-select the file if it moved or was deleted","Copy remote/network files locally before opening if the mount is unreliable"],"exampleFix":"// before\nlet doc_info = pdf::info(&path)?; // 'nao leu /x/arquivo.pdf: No such file'\n// after\nif !path.is_file() {\n    let picked = re_prompt_for_file()?;\n    return pdf::info(&picked);\n}\nlet doc_info = pdf::info(&path)?;","handlingStrategy":"try-catch","validationCode":"fn readable_pdf_path(p: &std::path::Path) -> Result<(), String> {\n    if !p.is_file() { return Err(format!(\"arquivo não encontrado: {}\", p.display())); }\n    std::fs::File::open(p).map(|_| ()).map_err(|e| format!(\"sem permissão de leitura em {}: {e}\", p.display()))\n}","typeGuard":null,"tryCatchPattern":"match pdf::info(&path) {\n    Err(e) if e.to_string().contains(\"nao leu \") => {\n        eprintln!(\"{e}\\nConfirme que o arquivo existe e é acessível; selecione-o novamente.\");\n        re_prompt_for_file()?;\n    }\n    other => other?,\n}","preventionTips":["Re-check existence right before opening; files can move between pick and use","Keep macOS security-scoped bookmarks for sandboxed file access","Copy files from unstable mounts (network/USB) to a temp dir first","Distinguish directories from files in file pickers"],"tags":["rust","io","pdf","file-read","filesystem"],"backgroundTag":"file-read-failed","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"}