{"record":{"id":"bd8eae2d6883bdfc","repo":"tonhowtf/omniget","slug":"modelo-desconhecido-id","errorCode":null,"errorMessage":"modelo desconhecido: {id}","messagePattern":"modelo desconhecido: (.+?)","errorType":"exception","errorClass":"anyhow","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/onnx.rs","lineNumber":194,"sourceCode":"    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]);\n    }\n    Ok(hex::encode(hasher.finalize()))\n}\n\n/// Garante o modelo no disco. Se já está lá com o tamanho certo, não baixa de\n/// novo. O sha256 é conferido no arquivo recém-baixado, antes de virar oficial.\npub async fn ensure_model(id: &str, progress: &ProgressFn) -> anyhow::Result<PathBuf> {\n    let spec = find(id).ok_or_else(|| anyhow!(\"modelo desconhecido: {id}\"))?;\n    let dest = model_path(id).ok_or_else(|| anyhow!(\"não achei o diretório de dados do app\"))?;\n    if is_downloaded(id) {\n        return Ok(dest);\n    }\n    let dir = dest\n        .parent()\n        .ok_or_else(|| anyhow!(\"caminho de modelo sem pasta\"))?\n        .to_path_buf();\n    std::fs::create_dir_all(&dir).with_context(|| format!(\"criando {}\", dir.display()))?;\n\n    let tmp = dir.join(format!(\".{id}.onnx.download\"));\n    let client = super::client()?;\n    let pid = format!(\"onnx-model:{id}\");\n    super::download_to(&client, spec.url, &tmp, progress, &pid).await?;\n\n    let expected = spec.sha256.to_string();\n    let tmp2 = tmp.clone();\n    let dest2 = dest.clone();","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/onnx.rs#L176-L212","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Get the valid ids from `onnx::status(None)` (the `models[].id` field) and use one of those exactly.","Fix the id spelling/casing to match the CATALOG entry (e.g. \"u2netp\").","If the model genuinely is missing from the catalog, add a ModelSpec entry (id, name, family, bytes, license, url, sha256) and rebuild."],"exampleFix":"// before\nlet p = onnx::ensure_model(\"u2net\", &progress).await?;\n// after\nlet valid: Vec<_> = onnx::status(None).models.iter().map(|m| m.id.clone()).collect();\nassert!(valid.contains(&\"u2netp\".to_string()), \"ids validos: {valid:?}\");\nlet p = onnx::ensure_model(\"u2netp\", &progress).await?;","handlingStrategy":"validation","validationCode":"let valid: Vec<String> = onnx::status(None).models.iter().map(|m| m.id.clone()).collect();\nif !valid.contains(&id.to_string()) {\n    return Err(anyhow!(\"id de modelo desconhecido '{id}'; validos: {valid:?}\"));\n}","typeGuard":"fn is_known_model(id: &str) -> bool {\n    onnx::status(None).models.iter().any(|m| m.id == id)\n}","tryCatchPattern":"match onnx::ensure_model(id, &progress).await {\n    Ok(path) => path,\n    Err(e) if e.to_string().starts_with(\"modelo desconhecido\") => {\n        eprintln!(\"use um id do catalogo: veja onnx::status(None)\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always take model ids from onnx::status() instead of hard-coding strings.","Keep catalog ids and frontend selectors in sync; generate the selector list from status().","When adding models, add a test that ensure_model accepts each catalog id."],"tags":["onnx","catalog","invalid-identifier","model-download"],"backgroundTag":"entity-not-found","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"}