{"record":{"id":"c1e15be90e0a4326","repo":"run-llama/liteparse","slug":"pdfium-not-loaded-call-pdfium-sys-dynamic-load","errorCode":null,"errorMessage":"pdfium not loaded — call pdfium_sys::dynamic::load_default() first","messagePattern":"pdfium not loaded — call pdfium_sys::dynamic::load_default\\(\\) first","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/pdfium-sys/src/dynamic.rs","lineNumber":966,"sourceCode":"            }\n        }\n    }\n\n    Err(format!(\n        \"could not find pdfium shared library. Last error: {last_err}. \\\n         Set PDFIUM_LIB_PATH to the directory containing {}\",\n        dylib_name()\n    ))\n}\n\n/// Get a reference to the loaded pdfium bindings.\n///\n/// # Panics\n/// Panics if `load()` or `load_default()` has not been called successfully.\npub fn pdfium() -> &'static PdfiumBindings {\n    BINDINGS\n        .get()\n        .expect(\"pdfium not loaded — call pdfium_sys::dynamic::load_default() first\")\n}\n","sourceCodeStart":948,"sourceCodeEnd":968,"githubUrl":"https://github.com/run-llama/liteparse/blob/22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8/crates/pdfium-sys/src/dynamic.rs#L948-L968","documentation":"`pdfium_sys::dynamic::pdfium()` returns the process-global handle to the dynamically loaded PDFium library, stored in a `OnceLock`-style static. It panics via `expect` when that static was never populated, i.e. neither `load()` nor `load_default()` completed successfully before any FFI call. It is an initialization-order bug: the library was used before the shared library was loaded.","triggerScenarios":"Calling any code path that reaches `dynamic::pdfium()` (direct FFI calls through the dynamic bindings) without first invoking `pdfium_sys::dynamic::load(path)` or `pdfium_sys::dynamic::load_default()` — or after a `load_default()` whose Err was ignored/unwrapped incorrectly.","commonSituations":"Calling low-level pdfium-sys APIs directly in tests or binaries without the init step that higher layers (like `Library::init`) normally perform; swallowing the Err from `load_default()` and continuing; running on a machine where loading silently failed earlier in the process lifetime.","solutions":["Call `pdfium_sys::dynamic::load_default()?` at process start and propagate/inspect the error before any PDFium usage.","Or call `pdfium_sys::dynamic::load(Path::new(\"/path/to/libpdfium.so\"))` with an explicit library path before using the bindings.","If using the higher-level liteparse-pdfium crate, call `Library::try_init()`/`Library::init()` first — it performs load_default() for you.","Ensure the PDFIUM_LIB_PATH env var points to the directory containing the shared library so load_default() succeeds."],"exampleFix":"// before\nlet bindings = pdfium_sys::dynamic::pdfium();\n// after\npdfium_sys::dynamic::load_default().expect(\"pdfium shared library must be available\");\nlet bindings = pdfium_sys::dynamic::pdfium();","handlingStrategy":"try-catch","validationCode":"// call before any pdfium usage\nfn ensure_pdfium_loaded() -> Result<(), String> {\n    pdfium_sys::dynamic::load_default()\n}","typeGuard":"// statics have no type guard; gate usage on an init flag\nstatic LOADED: OnceLock<()> = OnceLock::new();\nfn pdfium_ready() -> bool { LOADED.get().is_some() }","tryCatchPattern":"// catch_unwind around panic-based FFI access\nlet r = std::panic::catch_unwind(|| {\n    let _ = pdfium_sys::dynamic::pdfium();\n});\nif r.is_err() { pdfium_sys::dynamic::load_default().unwrap(); }","preventionTips":["Always call load_default()/load() as the first step of main() or a central init module","Never ignore the Err returned by load_default()","Prefer higher-level Library::try_init() which centralizes loading and error handling","Set PDFIUM_LIB_PATH in deployment environments so default loading succeeds"],"tags":["ffi","initialization","dynamic-loading","rust"],"backgroundTag":"module-init-failed","analyzedSha":"22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8","analyzedAt":"2026-09-08T06:09:49.009Z","contentChangedAt":"2026-09-08T06:09:49.009Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}