tonhowtf/omniget · error · anyhow

o modelo ainda não foi baixado (esperado em )

Error message

o modelo {id} ainda não foi baixado (esperado em {})

What it means

session_for returns this when the model id resolves to a valid app-data path but no file exists there — the model simply was not downloaded yet. The message includes the expected path so the user knows where the model should be. This is the expected 'not installed' state, not an internal failure.

Solutions

  1. Download the model first (the crate's download/download_model API) before requesting a session
  2. Check path existence and trigger the download flow automatically when the file is missing
  3. Verify the id matches the model that was actually downloaded (ids must be exact)
  4. If using a custom model, load it with session_from_file pointing at the user's file

Example fix

// before
let sess = tauri::async_runtime::spawn_blocking(move || onnx::session_for(id)).await??;
// after
if onnx::model_path(&id).map(|p| p.is_file()) != Some(true) {
    onnx::download(progress_cb, &id).await?; // fetch model first
}
let sess = tauri::async_runtime::spawn_blocking(move || onnx::session_for(id)).await??;
Defensive patterns

Strategy: validation

Validate before calling

fn ensure_model_downloaded(id: &str) -> anyhow::Result<()> {
    match onnx::model_path(id) {
        Some(p) if p.is_file() => Ok(()),
        Some(_) => Err(anyhow!("modelo {id} precisa ser baixado antes do uso")),
        None => Err(anyhow!("diretório de dados do app indisponível")),
    }
}

Try / catch

match onnx::session_for(id) {
    Err(e) if e.to_string().contains("ainda não foi baixado") => trigger_download_then_retry(id).await?,
    other => other?,
}

Prevention

When it happens

Trigger: Calling session_for(id) for a model id that was never downloaded, after the user manually deleted the model file, or after a failed/interrupted download left no file at the resolved path.

Common situations: Fresh install where the user asks for inference before downloading the model; switching machines or clearing app data; download canceled midway so the file never landed.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

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

    }
    Ok(())
}

/// Quantas threads dar ao ONNX Runtime. Deixa pelo menos um núcleo livre para
/// a interface não travar em lote grande.
fn intra_threads() -> usize {
    std::thread::available_parallelism()
        .map(|n| (n.get().saturating_sub(1)).max(1))
        .unwrap_or(1)
}

/// Sessão pronta para um modelo já baixado. Bloqueante: chame de dentro de um
/// `spawn_blocking`. A runtime é inicializada aqui, então um erro de lib
/// 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())

View on GitHub (pinned to 8600b91f42)