{"record":{"id":"22a2e4fe0a3f059f","repo":"tonhowtf/omniget","slug":"tarefa-de-remo-o-de-fundo-falhou-e","errorCode":null,"errorMessage":"tarefa de remoção de fundo falhou: {e}","messagePattern":"tarefa de remoção de fundo falhou: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/img_bg.rs","lineNumber":498,"sourceCode":"/// Ponto de entrada da tool. Garante runtime e modelo antes de qualquer\n/// inferência, e só então joga o trabalho pesado para uma thread de bloqueio.\npub async fn run(opts: BgOptions, progress: ProgressFn) -> anyhow::Result<BgResult> {\n    let model_id = if opts.model.trim().is_empty() {\n        default_model().to_string()\n    } else {\n        opts.model.trim().to_string()\n    };\n    if params_for(&model_id).is_none() {\n        return Err(anyhow!(\"o modelo {model_id} não serve para remover fundo\"));\n    }\n    // Erro acionável antes de baixar 180 MB à toa.\n    crate::core::onnxrt::init()?;\n    super::onnx::ensure_model(&model_id, &progress).await?;\n\n    let p = progress.clone();\n    tokio::task::spawn_blocking(move || run_blocking(&opts, &model_id, &p))\n        .await\n        .map_err(|e| anyhow!(\"tarefa de remoção de fundo falhou: {e}\"))?\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    fn gray(w: u32, h: u32, v: u8) -> GrayImage {\n        GrayImage::from_pixel(w, h, image::Luma([v]))\n    }\n\n    #[test]\n    fn cada_modelo_do_catalogo_rembg_tem_pre_processamento() {\n        for m in super::super::onnx::family(\"rembg\") {\n            let p = params_for(m.id)\n                .unwrap_or_else(|| panic!(\"modelo {} sem parâmetros de entrada\", m.id));\n            assert!(p.size >= 320);\n            assert!(p.std.iter().all(|s| *s > 0.0), \"desvio zero em {}\", m.id);\n        }","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/img_bg.rs#L480-L516","documentation":"run spawns run_blocking via tokio::task::spawn_blocking. If the spawned task itself panics (e.g. inside the ONNX inference or progress callback), the JoinHandle's await returns a JoinError, which run maps to this error containing the panic message. This is distinct from the inner anyhow error returned by run_blocking, which propagates unchanged.","triggerScenarios":"A panic inside run_blocking (unwrap on None, slice index out of bounds, ONNX runtime assertion) so the blocking task aborts instead of returning Err; also OS-level task spawn/abort issues.","commonSituations":"Bad ONNX model files causing panics in ort; images that decode to unexpected sizes; mutex poisoning unwrapped inside the blocking closure.","solutions":["Read the captured panic message after 'tarefa de remoção de fundo falhou:' to find the real cause","Fix the panicking code path in run_blocking (avoid unwrap/index panics on malformed inputs)","Validate input images (decodable, non-zero dimensions) before calling run","If the task was cancelled, ensure the future isn't dropped mid-await"],"exampleFix":"// before\nlet bytes = &image_bytes[10..];\n// after\nlet bytes = image_bytes.get(10..).ok_or_else(|| anyhow!(\"imagem truncada\"))?;","handlingStrategy":"try-catch","validationCode":"match run(&opts, &progress).await {\n    Err(e) if e.to_string().contains(\"tarefa de remoção de fundo falhou\") => {\n        // inspect panic cause after the colon\n    }\n    other => other?,\n}","typeGuard":null,"tryCatchPattern":"match run(&opts, &progress).await {\n    Ok(res) => handle(res),\n    Err(e) => {\n        let msg = format!(\"{e:#}\");\n        if msg.contains(\"tarefa de remoção de fundo falhou\") {\n            log::error!(\"panic in bg task: {msg}\");\n        }\n        bail!(msg);\n    }\n}","preventionTips":["Avoid unwrap/expect and unchecked indexing inside run_blocking","Validate/decode images before spawning the blocking task","Keep the blocking closure panic-free; return anyhow::Result instead"],"tags":["rust","tokio","panic","spawn-blocking"],"backgroundTag":"thread-interrupted","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"}