{"record":{"id":"7933b91ac3e9d234","repo":"tonhowtf/omniget","slug":"n-o-achei-o-diret-rio-de-dados-do-app-onnx","errorCode":null,"errorMessage":"não achei o diretório de dados do app","messagePattern":"não achei o diretório de dados do app","errorType":"exception","errorClass":"anyhow","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/onnx.rs","lineNumber":195,"sourceCode":"    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();\n    let p = progress.clone();","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/onnx.rs#L177-L213","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Create the expected app data directory manually if the resolver requires it to pre-exist.","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."],"exampleFix":"// before\nlet p = onnx::ensure_model(id, &progress).await?;\n// after\nif std::env::var_os(\"HOME\").is_none() {\n    std::env::set_var(\"HOME\", \"/tmp\"); // CI/headless fallback\n}\nlet p = onnx::ensure_model(id, &progress).await?;","handlingStrategy":"validation","validationCode":"// before downloading, confirm the app data dir resolves\nif onnx::status(None).models_dir.is_none() {\n    return Err(anyhow!(\"diretorio de dados do app indisponivel; verifique HOME/USERPROFILE\"));\n}","typeGuard":null,"tryCatchPattern":"match onnx::ensure_model(id, &progress).await {\n    Ok(p) => p,\n    Err(e) if e.to_string().contains(\"diretório de dados\") => {\n        eprintln!(\"configurar o diretorio de dados do app antes de baixar modelos\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Ensure HOME (Unix) / USERPROFILE (Windows) is set, exists, and is writable in headless/CI environments.","Check models_dir in onnx::status(None) during startup and fail fast with a clear message.","Avoid running the app under sandboxes that hide the user data directory."],"tags":["onnx","filesystem","app-data","environment"],"backgroundTag":"directory-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"}