tonhowtf/omniget · error · anyhow

não achei o diretório de dados do app

Error message

não achei o diretório de dados do app

What it means

After resolving the model spec, `ensure_model` calls `model_path(id)`, which is `models_dir().join(...)`; `models_dir()` is `tools_dir().map(...)` and returns None when the app data directory cannot be determined, producing 'não achei o diretório de dados do app'. This is an environment/configuration failure, not a model problem.

Solutions

  1. Ensure the user data directory is available: set HOME (Unix) or the equivalent env (USERPROFILE on Windows) and make sure it exists and is writable.
  2. Create the expected app data directory manually if the resolver requires it to pre-exist.
  3. Check how `tools_dir()` resolves (crate::core::tools) and confirm the environment satisfies it; file a fix to fall back to a temp dir if that fits your deployment.

Example fix

// before
let p = onnx::ensure_model(id, &progress).await?;
// after
if std::env::var_os("HOME").is_none() {
    std::env::set_var("HOME", "/tmp"); // CI/headless fallback
}
let p = onnx::ensure_model(id, &progress).await?;
Defensive patterns

Strategy: validation

Validate before calling

// before downloading, confirm the app data dir resolves
if onnx::status(None).models_dir.is_none() {
    return Err(anyhow!("diretorio de dados do app indisponivel; verifique HOME/USERPROFILE"));
}

Try / catch

match onnx::ensure_model(id, &progress).await {
    Ok(p) => p,
    Err(e) if e.to_string().contains("diretório de dados") => {
        eprintln!("configurar o diretorio de dados do app antes de baixar modelos");
        return Err(e);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling `ensure_model` (or `remove_model`, which reuses the same message) on a system where the app's tools/data directory cannot be resolved — e.g. missing XDG data home with no fallback, sandboxed environment without an app-data path, or a corrupted tools_dir resolution.

Common situations: Running the app headless/CI with HOME unset or read-only; unusual platform where the Tauri app-data path is unavailable; custom portable deployments without the expected directory layout.

Related errors


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

Appendix: source

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

    let mut file = std::fs::File::open(path)
        .with_context(|| format!("abrindo {} para conferir o sha256", path.display()))?;
    let mut hasher = Sha256::new();
    let mut buf = vec![0u8; 1 << 20];
    loop {
        let n = file.read(&mut buf)?;
        if n == 0 {
            break;
        }
        hasher.update(&buf[..n]);
    }
    Ok(hex::encode(hasher.finalize()))
}

/// Garante o modelo no disco. Se já está lá com o tamanho certo, não baixa de
/// novo. O sha256 é conferido no arquivo recém-baixado, antes de virar oficial.
pub async fn ensure_model(id: &str, progress: &ProgressFn) -> anyhow::Result<PathBuf> {
    let spec = find(id).ok_or_else(|| anyhow!("modelo desconhecido: {id}"))?;
    let dest = model_path(id).ok_or_else(|| anyhow!("não achei o diretório de dados do app"))?;
    if is_downloaded(id) {
        return Ok(dest);
    }
    let dir = dest
        .parent()
        .ok_or_else(|| anyhow!("caminho de modelo sem pasta"))?
        .to_path_buf();
    std::fs::create_dir_all(&dir).with_context(|| format!("criando {}", dir.display()))?;

    let tmp = dir.join(format!(".{id}.onnx.download"));
    let client = super::client()?;
    let pid = format!("onnx-model:{id}");
    super::download_to(&client, spec.url, &tmp, progress, &pid).await?;

    let expected = spec.sha256.to_string();
    let tmp2 = tmp.clone();
    let dest2 = dest.clone();
    let p = progress.clone();

View on GitHub (pinned to 8600b91f42)