{"record":{"id":"8e6caff3ecf7c968","repo":"tonhowtf/omniget","slug":"o-modelo-model-id-n-o-serve-para-remover-fundo","errorCode":null,"errorMessage":"o modelo {model_id} não serve para remover fundo","messagePattern":"o modelo (.+?) não serve para remover fundo","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/img_bg.rs","lineNumber":410,"sourceCode":"    let h = shape[shape.len() - 2].max(0) as u32;\n    let w = shape[shape.len() - 1].max(0) as u32;\n    let small = mask_from_raw(raw, w, h)?;\n    let (ow, oh) = (img.width(), img.height());\n    Ok(image::imageops::resize(\n        &small,\n        ow,\n        oh,\n        FilterType::Lanczos3,\n    ))\n}\n\nfn run_blocking(\n    opts: &BgOptions,\n    model_id: &str,\n    progress: &ProgressFn,\n) -> anyhow::Result<BgResult> {\n    let params = *params_for(model_id)\n        .ok_or_else(|| anyhow!(\"o modelo {model_id} não serve para remover fundo\"))?;\n    let files = collect_inputs(&opts.inputs, &opts.input_dir);\n    if files.is_empty() {\n        return Err(anyhow!(\"escolha ao menos uma imagem\"));\n    }\n    let background = parse_hex_color(&opts.background)?;\n    let ext = resolve_format(&opts.format, background.is_some(), opts.mask_only);\n\n    let mut session = super::onnx::session_for(model_id)?;\n    let total = files.len() as u64;\n    let mut items: Vec<BgItem> = Vec::with_capacity(files.len());\n    let mut failed = 0usize;\n\n    for (i, path) in files.iter().enumerate() {\n        super::report(\n            progress,\n            TOOL_ID,\n            \"progress\",\n            i as u64,","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/img_bg.rs#L392-L428","documentation":"A lookup failure in `run_blocking`: `params_for(model_id)` returned None, so the given model_id is not a registered background-removal model. The tool only supports a fixed set of model ids, and any other string is rejected before a session is created.","triggerScenarios":"Calling `run_blocking` (via `run`) with a model_id string that is not one of the keys returned by `params_for` — e.g. a typo, a model id from another tool (super-resolution, upscaling), or a user-supplied id passed through unvalidated from the UI.","commonSituations":"Frontend sending a model dropdown value that was renamed; config file or CLI flag holding an old model id after a rename; passing an arbitrary downloaded model filename as model_id.","solutions":["Use one of the model ids supported by `params_for` (check its match arms/keys in this file)","Validate the model_id in the UI/CLI layer against the same list before calling `run`","If a new model was added, register it in `params_for` with its size and normalization params","Log or surface the list of valid model ids in the error to make the typo obvious"],"exampleFix":"// before\nrun(&opts, \"isnet-general-use-v2\")?; // id not registered\n// after\nlet valid = params_for_keys(); // e.g. [\"u2net\", \"isnet-general-use\"]\nassert!(valid.contains(&\"isnet-general-use\"));\nrun(&opts, \"isnet-general-use\")?;","handlingStrategy":"validation","validationCode":"let supported = [\"u2net\", \"isnet-general-use\", \"isnet-anime\"];\nif !supported.contains(&model_id) {\n    return Err(anyhow!(\"model_id '{model_id}' inválido; use um de: {supported:?}\"));\n}","typeGuard":"fn is_valid_model_id(id: &str) -> bool {\n    params_for(id).is_some()\n}","tryCatchPattern":null,"preventionTips":["Derive UI dropdown options from the same source as params_for","Add a unit test asserting every exposed model_id has params","Include the list of valid ids in the error message for easier debugging"],"tags":["configuration","model","validation","lookup"],"backgroundTag":"invalid-enum-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"}