{"record":{"id":"403224c7beda08e3","repo":"tonhowtf/omniget","slug":"nao-carregou-o-pdfium-em","errorCode":null,"errorMessage":"nao carregou o PDFium em {}: {}","messagePattern":"nao carregou o PDFium em (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":126,"sourceCode":"    Ok(*lib\n        .get::<T>(name)\n        .map_err(|e| anyhow!(\"PDFium sem {}: {}\", String::from_utf8_lossy(name), e))?)\n}\n\n/// Igual ao `sym`, mas o símbolo pode faltar: devolve `None` em vez de erro.\nunsafe fn opt_sym<T: Copy>(lib: &libloading::Library, name: &[u8]) -> Option<T> {\n    lib.get::<T>(name).ok().map(|s| *s)\n}\n\nfn api() -> anyhow::Result<&'static Api> {\n    let mut guard = API.lock().unwrap_or_else(|p| p.into_inner());\n    if let Some(a) = *guard {\n        return Ok(a);\n    }\n    let path = crate::core::pdfium::resolve_path()\n        .ok_or_else(|| anyhow!(\"PDFium nao esta instalado (Ajustes → Dependencias → PDFium)\"))?;\n    let lib = unsafe { libloading::Library::new(&path) }\n        .map_err(|e| anyhow!(\"nao carregou o PDFium em {}: {}\", path.display(), e))?;\n    let api = unsafe {\n        let init: unsafe extern \"C\" fn() = sym(&lib, b\"FPDF_InitLibrary\\0\")?;\n        init();\n        Api {\n            load_mem: sym(&lib, b\"FPDF_LoadMemDocument64\\0\")?,\n            last_error: sym(&lib, b\"FPDF_GetLastError\\0\")?,\n            page_count: sym(&lib, b\"FPDF_GetPageCount\\0\")?,\n            load_page: sym(&lib, b\"FPDF_LoadPage\\0\")?,\n            page_w: sym(&lib, b\"FPDF_GetPageWidthF\\0\")?,\n            page_h: sym(&lib, b\"FPDF_GetPageHeightF\\0\")?,\n            close_page: sym(&lib, b\"FPDF_ClosePage\\0\")?,\n            close_doc: sym(&lib, b\"FPDF_CloseDocument\\0\")?,\n            bmp_create: sym(&lib, b\"FPDFBitmap_Create\\0\")?,\n            bmp_fill: sym(&lib, b\"FPDFBitmap_FillRect\\0\")?,\n            render: sym(&lib, b\"FPDF_RenderPageBitmap\\0\")?,\n            bmp_buffer: sym(&lib, b\"FPDFBitmap_GetBuffer\\0\")?,\n            bmp_stride: sym(&lib, b\"FPDFBitmap_GetStride\\0\")?,\n            bmp_destroy: sym(&lib, b\"FPDFBitmap_Destroy\\0\")?,","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L108-L144","documentation":"api() wraps libloading::Library::new failure with this message after a path was resolved. The library file was found but could not be loaded as a dynamic library — wrong architecture, missing transitive dependencies, corrupted file, or insufficient permissions. The message includes the path and the OS loader error, which is the key diagnostic.","triggerScenarios":"Calling any PDF operation when the resolved PDFium file cannot be dlopen'd/LoadLibrary'd: 32/64-bit mismatch, missing libstdc++/libc++ deps of pdfium, quarantine/provisioning blocking load on macOS, truncated download.","commonSituations":"Downloading the wrong-architecture pdfium binary; on Linux missing system libs pdfium links against; macOS Gatekeeper quarantine bit; partially downloaded library file.","solutions":["Read the inner libloading/OS error in the message to identify the load failure cause","Install the PDFium build matching the app's architecture and platform","On Linux install missing shared-library dependencies (ldd the pdfium file); on macOS clear the quarantine attribute (xattr -d com.apple.quarantine)","Re-download/reinstall PDFium — the file may be truncated or corrupted"],"exampleFix":"// before\nlet pages = pdf::render(path, opts)?; // 'nao carregou o PDFium em /opt/.../libpdfium.so: ...'\n// after\nmatch pdf::render(path, opts) {\n    Err(e) if e.to_string().contains(\"nao carregou o PDFium\") => {\n        repair_pdfium_install()?; // reinstall correct arch + deps\n        let pages = pdf::render(path, opts)?;\n    }\n    r => r?,\n}","handlingStrategy":"try-catch","validationCode":"fn pdfium_loadable(p: &std::path::Path) -> Result<(), String> {\n    // loader-level probe\n    match unsafe { libloading::Library::new(p) } {\n        Ok(_) => Ok(()),\n        Err(e) => Err(format!(\"falha ao carregar {}: {e}\\nVerifique arquitetura e dependências do sistema.\", p.display())),\n    }\n}","typeGuard":null,"tryCatchPattern":"match pdf::split(&path, &out_dir) {\n    Err(e) if e.to_string().contains(\"nao carregou o PDFium\") => {\n        eprintln!(\"{e}\\nReinstale o PDFium da arquitetura correta via Ajustes → Dependências.\");\n    }\n    other => other?,\n}","preventionTips":["Distribute per-architecture PDFium builds and verify with ldd/otool in CI","On macOS strip the quarantine bit from bundled dylibs","Handle partial downloads of the library atomically (download to temp, then rename)","Keep the loader error visible to the user for support diagnostics"],"tags":["rust","pdfium","libloading","dynamic-library","load-failure"],"backgroundTag":"library-load-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"}