{"record":{"id":"3408aa9b48c56c36","repo":"tonhowtf/omniget","slug":"n-o-consegui-carregar","errorCode":null,"errorMessage":"não consegui carregar {}: {}","messagePattern":"não consegui carregar (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/onnxrt.rs","lineNumber":289,"sourceCode":"    }\n}\n\n/// Caminho que o `ort` já está usando, quando o carregamento deu certo uma vez.\nstatic READY: OnceLock<PathBuf> = OnceLock::new();\n\n/// Aponta o `ort` para a lib resolvida. Idempotente: o `ort` guarda o handle\n/// num `OnceLock` próprio, então a segunda chamada não troca nada — por isso\n/// guardamos o caminho que venceu e devolvemos ele.\n///\n/// Falta de lib vira erro acionável, nunca panic: o `ort` só entra em pânico\n/// se alguém tocar na API dele sem passar por aqui.\npub fn init() -> anyhow::Result<PathBuf> {\n    if let Some(p) = READY.get() {\n        return Ok(p.clone());\n    }\n    let path = resolve_path().ok_or_else(missing_runtime_error)?;\n    ort::init_from(&path)\n        .map_err(|e| anyhow!(\"não consegui carregar {}: {}\", path.display(), e))?\n        .with_name(\"omniget\")\n        .commit();\n    let _ = READY.set(path.clone());\n    Ok(path)\n}\n\nfn sha256_of(path: &Path) -> anyhow::Result<String> {\n    use sha2::{Digest, Sha256};\n    let mut file = std::fs::File::open(path)\n        .with_context(|| format!(\"abrindo {} para conferir o sha256\", path.display()))?;\n    let mut hasher = Sha256::new();\n    let mut buf = vec![0u8; 1 << 20];\n    loop {\n        let n = file.read(&mut buf)?;\n        if n == 0 {\n            break;\n        }\n        hasher.update(&buf[..n]);","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/onnxrt.rs#L271-L307","documentation":"Raised by init() when the ONNX Runtime shared library path was resolved but ort::init_from(path) fails to load the native library (e.g. the file is not a valid shared object, wrong architecture, or missing dependent libs). The error wraps the underlying ort error with the path that failed.","triggerScenarios":"init() called with READY unset; resolve_path() returned a path, but ort::init_from(...).commit() fails — file corrupt/truncated, wrong-arch binary, missing transitive dependencies (libc versions, ICU), or a text file masquerading as the lib.","commonSituations":"Interrupted download leaving a truncated .so; copied a lib from a different OS/arch; pointing config at a stub or LSP file instead of the real library; a partial upgrade replacing the lib with an incompatible version.","solutions":["Delete the installed library in the app data dir and reinstall the runtime from the Models screen","Verify the file is a real shared library for this OS/arch (file onnxruntime.so / otool -L)","Install OS dependencies the library needs (e.g. libstdc++, glibc)","Point install_from_path at a known-good lib (e.g. from the pip onnxruntime package)"],"exampleFix":"// before\nlet p = onnxrt::init()?; // \"não consegui carregar ...: dlopen failed\"\n// after\nlet lib = find_configured_lib();\nmatch std::fs::metadata(&lib) { Ok(m) if m.len() < 1_000_000 => reinstall_runtime().await?, _ => {} }\nlet p = onnxrt::init()?;","handlingStrategy":"validation","validationCode":"let ok = std::fs::read(path, ..).map(|b| b.len() > 1_000_000).unwrap_or(false);","typeGuard":"fn is_likely_elf(p: &Path) -> bool { std::fs::read(p).ok().and_then(|b| b.first().map(|c| *c == 0x7f)).unwrap_or(false) }","tryCatchPattern":"match onnxrt::init() { Err(e) if e.to_string().contains(\"não consegui carregar\") => { reinstall_runtime().await?; onnxrt::init() } ... }","preventionTips":["Verify the library size/hash after download before committing","Install OS native dependencies the runtime links against","Never hand-edit or truncate the installed library"],"tags":["onnx","rust","native-library","dlopen"],"backgroundTag":"module-init-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"}