tonhowtf/omniget · error · anyhow

modelo desconhecido

Error message

modelo desconhecido: {id}

What it means

`onnx::ensure_model` looks up `id` in the compiled model CATALOG via `find(id)`; an unknown id yields 'modelo desconhecido: {id}'. Only models present in the built-in catalog (with url, sha256, and expected size) can be downloaded.

Solutions

  1. Get the valid ids from `onnx::status(None)` (the `models[].id` field) and use one of those exactly.
  2. Fix the id spelling/casing to match the CATALOG entry (e.g. "u2netp").
  3. If the model genuinely is missing from the catalog, add a ModelSpec entry (id, name, family, bytes, license, url, sha256) and rebuild.

Example fix

// before
let p = onnx::ensure_model("u2net", &progress).await?;
// after
let valid: Vec<_> = onnx::status(None).models.iter().map(|m| m.id.clone()).collect();
assert!(valid.contains(&"u2netp".to_string()), "ids validos: {valid:?}");
let p = onnx::ensure_model("u2netp", &progress).await?;
Defensive patterns

Strategy: validation

Validate before calling

let valid: Vec<String> = onnx::status(None).models.iter().map(|m| m.id.clone()).collect();
if !valid.contains(&id.to_string()) {
    return Err(anyhow!("id de modelo desconhecido '{id}'; validos: {valid:?}"));
}

Type guard

fn is_known_model(id: &str) -> bool {
    onnx::status(None).models.iter().any(|m| m.id == id)
}

Try / catch

match onnx::ensure_model(id, &progress).await {
    Ok(path) => path,
    Err(e) if e.to_string().starts_with("modelo desconhecido") => {
        eprintln!("use um id do catalogo: veja onnx::status(None)");
        return Err(e);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling `ensure_model(id, progress)` (directly or through the download command that the test `baixa_o_u2netp_e_o_sha256_bate` exercises) with an id string that does not match any catalog entry — typos, wrong casing, or an id from a newer/older app version.

Common situations: Hard-coded model ids that drifted from the catalog; user-supplied model names passed through from the frontend; catalog pruned between app versions so previously valid ids now fail.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

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

    use sha2::{Digest, Sha256};
    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();

View on GitHub (pinned to 8600b91f42)