{"record":{"id":"a3b25a2f329b956a","repo":"tonhowtf/omniget","slug":"n-o-gravei-o-jpeg","errorCode":null,"errorMessage":"não gravei o JPEG {}: {}","messagePattern":"não gravei o JPEG (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/img_bg.rs","lineNumber":356,"sourceCode":"    if wants_jpeg && (has_background || mask_only) {\n        \"jpg\"\n    } else {\n        \"png\"\n    }\n}\n\nfn save_image(img: &DynamicImage, dest: &Path, ext: &str, quality: u8) -> anyhow::Result<u64> {\n    if let Some(parent) = dest.parent() {\n        std::fs::create_dir_all(parent).with_context(|| format!(\"criando {}\", parent.display()))?;\n    }\n    if ext == \"jpg\" {\n        let file =\n            std::fs::File::create(dest).with_context(|| format!(\"criando {}\", dest.display()))?;\n        let mut w = std::io::BufWriter::new(file);\n        let mut enc =\n            image::codecs::jpeg::JpegEncoder::new_with_quality(&mut w, quality.clamp(1, 100));\n        enc.encode_image(&img.to_rgb8())\n            .map_err(|e| anyhow!(\"não gravei o JPEG {}: {}\", dest.display(), e))?;\n    } else {\n        img.save_with_format(dest, image::ImageFormat::Png)\n            .map_err(|e| anyhow!(\"não gravei o PNG {}: {}\", dest.display(), e))?;\n    }\n    Ok(std::fs::metadata(dest).map(|m| m.len()).unwrap_or(0))\n}\n\n// ── Execução ───────────────────────────────────────────────────────────\n\n/// Roda a inferência num arquivo já aberto e devolve a máscara no tamanho\n/// original da imagem.\nfn mask_for_image(\n    session: &mut ort::session::Session,\n    img: &DynamicImage,\n    p: &BgParams,\n) -> anyhow::Result<GrayImage> {\n    let side = p.size as i64;\n    // O `ort` traz um `ndarray` próprio (0.17) e o crate usa o 0.16, então o","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/img_bg.rs#L338-L374","documentation":"`save_image` uses JpegEncoder to write JPEG output; if `enc.encode_image(&img.to_rgb8())` fails, it wraps the error as 'não gravei o JPEG {path}: {e}'. The file was created, but pixel encoding/writing into the BufWriter failed.","triggerScenarios":"Calling `save_image` with a .jpg/.jpeg destination where JPEG encoding fails — typically an I/O error on the underlying writer (disk full, permissions revoked after create), or an image the JPEG encoder can't handle.","commonSituations":"Disk full when saving large result images; antivirus/backup tooling locking the freshly created file; destination on a flaky network mount.","solutions":["Check the wrapped inner error: if it's I/O, free disk space or fix permissions on the destination directory.","Retry saving to a different local path (e.g. temp dir) to rule out mount/lock issues.","Reduce image size or save as PNG (the tool's non-jpeg branch) if the JPEG encoder rejects the content."],"exampleFix":"// before\nlet dest = Path::new(\"/mnt/network/out.jpg\");\nsave_image(&img, dest, 90)?;\n// after\nlet dest = std::env::temp_dir().join(\"out.jpg\"); // reliable local path\nif let Err(e) = save_image(&img, dest, 90) {\n    eprintln!(\"falha ao salvar JPEG: {e:#}\");\n}","handlingStrategy":"try-catch","validationCode":"let meta = std::fs::metadata(dest.parent().unwrap())?;\n// ensure destination dir writable\nlet probe = dest.parent().unwrap().join(\".write_probe\");\nstd::fs::write(&probe, b\"\").map_err(|e| format!(\"destino sem permissão: {e}\"))?\n;let _ = std::fs::remove_file(&probe);","typeGuard":null,"tryCatchPattern":"if let Err(e) = save_image(&img, dest, quality) {\n    if e.to_string().contains(\"não gravei o JPEG\") {\n        eprintln!(\"falha ao escrever JPEG em {}: {e:#}\", dest.display());\n        // fallback to a temp dir or another volume\n    }\n}","preventionTips":["Check free disk space before writing large outputs","Save to a local temp file then atomically rename into place","Avoid network mounts as direct save destinations"],"tags":["file-io","jpeg","image-encoding","rust"],"backgroundTag":"file-write-failed","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"}