tonhowtf/omniget · error · anyhow

não criei o builder de sessão ONNX: {e}

Error message

não criei o builder de sessão ONNX: {e}

What it means

session_from_file wraps ort::session::Session::builder() (and builder configuration) failures with this message. It means the ONNX Runtime C API refused to create a session builder — typically the runtime shared library is missing, incompatible, or could not be initialized. The preceding crate::core::onnxrt::init() should surface library-loading problems with an actionable message, so this error usually means a deeper runtime/environment problem.

Solutions

  1. Verify the onnxruntime shared library is bundled and loadable (run the onnxrt init check and read its actionable message)
  2. Match the ort crate version to the bundled ONNX Runtime version (ort requires exact-major compatibility)
  3. Check the library architecture matches the binary (x86_64 vs arm64)
  4. Reinstall/rebundle the app so the runtime dependency is present

Example fix

// before
let sess = onnx::session_from_file(&path)?; // 'não criei o builder de sessão ONNX: ...'
// after
match onnx::session_from_file(&path) {
    Ok(s) => s,
    Err(e) => return Err(anyhow!("ONNX Runtime indisponível: {e}. Reinstale as dependências.")),
}
Defensive patterns

Strategy: try-catch

Validate before calling

// fail fast at startup if the ONNX runtime is unavailable
crate::core::onnxrt::init().map_err(|e| eprintln!("ONNX Runtime indisponível: {e}"))?;

Try / catch

match onnx::session_from_file(&path) {
    Err(e) if e.to_string().contains("não criei o builder") => Err(anyhow!("ONNX Runtime não inicializado: reinstale as dependências. Detalhe: {e}")),
    other => other,
}

Prevention

When it happens

Trigger: Calling session_from_file (or session_for) when the ONNX Runtime native library is absent/failed to load, the bundled ort build mismatches the runtime lib version, or the ORT environment cannot initialize in this process.

Common situations: Missing or wrong-architecture onnxruntime shared library on PATH/beside the binary; ort crate version vs runtime .so/.dll version mismatch (ORT aborts on mismatched API version); corrupted or partial app bundle missing the runtime.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/382422bb732d912b. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/onnx.rs:282

/// faltando sai com a mensagem acionável do `onnxrt`, não como panic.
pub fn session_for(id: &str) -> anyhow::Result<ort::session::Session> {
    let path = model_path(id).ok_or_else(|| anyhow!("não achei o diretório de dados do app"))?;
    if !path.is_file() {
        return Err(anyhow!(
            "o modelo {id} ainda não foi baixado (esperado em {})",
            path.display()
        ));
    }
    crate::core::onnxrt::init()?;
    session_from_file(&path)
}

/// Sessão a partir de um arquivo qualquer — útil para modelo que o usuário
/// aponta e para os testes.
pub fn session_from_file(path: &std::path::Path) -> anyhow::Result<ort::session::Session> {
    use ort::session::builder::GraphOptimizationLevel;
    let mut builder = ort::session::Session::builder()
        .map_err(|e| anyhow!("não criei o builder de sessão ONNX: {e}"))?
        // Builds mínimos do ONNX Runtime não têm otimização de grafo; nesse
        // caso o `ort` devolve o próprio builder de volta, então seguimos.
        .with_optimization_level(GraphOptimizationLevel::Level3)
        .unwrap_or_else(|e| e.recover())
        .with_intra_threads(intra_threads())
        .unwrap_or_else(|e| e.recover());
    builder
        .commit_from_file(path)
        .map_err(|e| anyhow!("não carreguei o modelo {}: {}", path.display(), e))
}

#[cfg(test)]
mod tests {
    use super::*;

    /// Release de onde todo modelo desta rodada sai. Fica no teste porque é
    /// invariante a conferir, não valor a montar URL em tempo de execução.
    const REMBG_BASE: &str = "https://github.com/danielgatis/rembg/releases/download/v0.0.0";

View on GitHub (pinned to 8600b91f42)