tonhowtf/omniget · error
tarefa de remoção de fundo falhou
Error message
tarefa de remoção de fundo falhou: {e} What it means
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.
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
Example fix
// before
let bytes = &image_bytes[10..];
// after
let bytes = image_bytes.get(10..).ok_or_else(|| anyhow!("imagem truncada"))?; Defensive patterns
Strategy: try-catch
Validate before calling
match run(&opts, &progress).await {
Err(e) if e.to_string().contains("tarefa de remoção de fundo falhou") => {
// inspect panic cause after the colon
}
other => other?,
} Try / catch
match run(&opts, &progress).await {
Ok(res) => handle(res),
Err(e) => {
let msg = format!("{e:#}");
if msg.contains("tarefa de remoção de fundo falhou") {
log::error!("panic in bg task: {msg}");
}
bail!(msg);
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Bad ONNX model files causing panics in ort; images that decode to unexpected sizes; mutex poisoning unwrapped inside the blocking closure.
Related errors
- spawn_blocking failed
- Spawn blocking failed
- worker task panicked
- spawn_blocking failed
- Spawn blocking failed
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/22a2e4fe0a3f059f.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/img_bg.rs:498
/// Ponto de entrada da tool. Garante runtime e modelo antes de qualquer
/// inferência, e só então joga o trabalho pesado para uma thread de bloqueio.
pub async fn run(opts: BgOptions, progress: ProgressFn) -> anyhow::Result<BgResult> {
let model_id = if opts.model.trim().is_empty() {
default_model().to_string()
} else {
opts.model.trim().to_string()
};
if params_for(&model_id).is_none() {
return Err(anyhow!("o modelo {model_id} não serve para remover fundo"));
}
// Erro acionável antes de baixar 180 MB à toa.
crate::core::onnxrt::init()?;
super::onnx::ensure_model(&model_id, &progress).await?;
let p = progress.clone();
tokio::task::spawn_blocking(move || run_blocking(&opts, &model_id, &p))
.await
.map_err(|e| anyhow!("tarefa de remoção de fundo falhou: {e}"))?
}
#[cfg(test)]
mod tests {
use super::*;
fn gray(w: u32, h: u32, v: u8) -> GrayImage {
GrayImage::from_pixel(w, h, image::Luma([v]))
}
#[test]
fn cada_modelo_do_catalogo_rembg_tem_pre_processamento() {
for m in super::super::onnx::family("rembg") {
let p = params_for(m.id)
.unwrap_or_else(|| panic!("modelo {} sem parâmetros de entrada", m.id));
assert!(p.size >= 320);
assert!(p.std.iter().all(|s| *s > 0.0), "desvio zero em {}", m.id);
}View on GitHub (pinned to 8600b91f42)