{"record":{"id":"63d271fea0cca70d","repo":"tonhowtf/omniget","slug":"n-o-carreguei-o-modelo","errorCode":null,"errorMessage":"não carreguei o modelo {}: {}","messagePattern":"não carreguei o modelo (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/onnx.rs","lineNumber":291,"sourceCode":"    crate::core::onnxrt::init()?;\n    session_from_file(&path)\n}\n\n/// Sessão a partir de um arquivo qualquer — útil para modelo que o usuário\n/// aponta e para os testes.\npub fn session_from_file(path: &std::path::Path) -> anyhow::Result<ort::session::Session> {\n    use ort::session::builder::GraphOptimizationLevel;\n    let mut builder = ort::session::Session::builder()\n        .map_err(|e| anyhow!(\"não criei o builder de sessão ONNX: {e}\"))?\n        // Builds mínimos do ONNX Runtime não têm otimização de grafo; nesse\n        // caso o `ort` devolve o próprio builder de volta, então seguimos.\n        .with_optimization_level(GraphOptimizationLevel::Level3)\n        .unwrap_or_else(|e| e.recover())\n        .with_intra_threads(intra_threads())\n        .unwrap_or_else(|e| e.recover());\n    builder\n        .commit_from_file(path)\n        .map_err(|e| anyhow!(\"não carreguei o modelo {}: {}\", path.display(), e))\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    /// Release de onde todo modelo desta rodada sai. Fica no teste porque é\n    /// invariante a conferir, não valor a montar URL em tempo de execução.\n    const REMBG_BASE: &str = \"https://github.com/danielgatis/rembg/releases/download/v0.0.0\";\n\n    #[test]\n    fn o_catalogo_tem_id_unico_sha256_e_tamanho() {\n        assert!(!CATALOG.is_empty());\n        let mut ids: Vec<&str> = CATALOG.iter().map(|m| m.id).collect();\n        ids.sort_unstable();\n        let antes = ids.len();\n        ids.dedup();\n        assert_eq!(antes, ids.len(), \"id de modelo repetido\");","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/onnx.rs#L273-L309","documentation":"session_from_file wraps builder.commit_from_file(path) failure with this message. The ONNX Runtime accepted a session builder but refused to load/commit the model file at the given path. This reports the file path plus the underlying ORT error, so the ORT detail (e.g. 'no such file', 'Protobuf parsing failed') is the real diagnostic.","triggerScenarios":"Calling session_from_file (or session_for) with a path that does not exist, points to a corrupt/truncated .onnx file, or contains a graph unsupported by this ONNX Runtime version/opset.","commonSituations":"Downloaded model file truncated by an interrupted download; user points the app at a non-ONNX file (e.g. .pt or .pb); model exported with a newer opset than the bundled runtime supports.","solutions":["Verify the file exists and is a complete .onnx file (re-download if size looks truncated)","Re-export the model with an opset/IR version supported by the bundled ONNX Runtime","Confirm the path is correct and readable by the process (permissions)","Update the bundled onnxruntime to a version matching the model's opset"],"exampleFix":"// before\nlet sess = onnx::session_from_file(Path::new(user_path))?; // 'não carreguei o modelo ...'\n// after\nlet p = Path::new(user_path);\nif !p.is_file() {\n    return Err(anyhow!(\"arquivo de modelo não encontrado: {}\", p.display()));\n}\nlet sess = onnx::session_from_file(p).map_err(|e| anyhow!(\"{e}; verifique se o arquivo é um .onnx válido\"))?;","handlingStrategy":"validation","validationCode":"fn valid_model_file(p: &std::path::Path) -> bool {\n    use std::io::Read;\n    let mut f = match std::fs::File::open(p) { Ok(f) => f, Err(_) => return false };\n    let mut head = [0u8; 4];\n    f.read_exact(&mut head).is_ok() // basic existence/readability check; full validation needs ORT\n        && std::fs::metadata(p).map(|m| m.len() > 0).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match onnx::session_from_file(&path) {\n    Err(e) if e.to_string().starts_with(\"não carreguei o modelo\") => {\n        eprintln!(\"{e}\\nVerifique se o arquivo é um modelo ONNX válido e não está truncado.\");\n    }\n    other => other?,\n}","preventionTips":["Validate downloaded model files (size/checksum) before use","Re-download truncated models automatically","Only accept .onnx files from user file pickers (extension filter + header check)","Keep bundled onnxruntime version compatible with your models' opsets"],"tags":["rust","ort","onnx","model-loading","invalid-model-file"],"backgroundTag":"invalid-argument-value","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"}