{"record":{"id":"b544302aee54259d","repo":"tonhowtf/omniget","slug":"n-o-gravei","errorCode":null,"errorMessage":"não gravei {}: {}","messagePattern":"não gravei (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf_form.rs","lineNumber":695,"sourceCode":"\n    // O leitor tem que redesenhar a aparência com o valor novo.\n    if let Ok(root) = doc.catalog_mut() {\n        if let Ok(Object::Reference(r)) = root.get(b\"AcroForm\").cloned() {\n            if let Ok(Object::Dictionary(form)) = doc.get_object_mut(r) {\n                form.set(\"NeedAppearances\", Object::Boolean(true));\n            }\n        } else if let Ok(Object::Dictionary(form)) = doc.catalog_mut()?.get_mut(b\"AcroForm\") {\n            form.set(\"NeedAppearances\", Object::Boolean(true));\n        }\n    }\n\n    if opts.flatten {\n        flatten(&mut doc, &stamps, opts.font_size)?;\n    }\n\n    let output = out_path(opts)?;\n    doc.save(&output)\n        .map_err(|e| anyhow!(\"não gravei {}: {}\", output.display(), e))?;\n    super::report(progress, ID, \"done\", total, Some(total), None);\n    Ok(FillResult {\n        input: opts.input.clone(),\n        output: output.to_string_lossy().to_string(),\n        fields: known.len(),\n        filled,\n        flattened: opts.flatten,\n        missing,\n    })\n}\n\n/// Desenha os valores nas páginas e apaga o formulário inteiro.\nfn flatten(\n    doc: &mut Document,\n    stamps: &[(usize, [f32; 4], String, bool)],\n    font_size: f32,\n) -> anyhow::Result<()> {\n    let ids: Vec<(u32, ObjectId)> = doc.get_pages().into_iter().collect();","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf_form.rs#L677-L713","documentation":"At the end of fill(), after fields are written and optionally flattened, doc.save(&output) is attempted and any Err is mapped to 'não gravei {path}: {inner}'. The error means the in-memory document could not be persisted to the chosen output path.","triggerScenarios":"The output directory (out_path(opts), typically a temp/cache dir) does not exist or was deleted; the process lacks write permission on the target directory; the output file is locked/open in another program (e.g. a PDF viewer on Windows) or is read-only; the disk is full.","commonSituations":"Antivirus or backup tools temporarily locking the output file; the app's data directory not yet created on first run; running with a different user/service account lacking permissions; saving onto a read-only mount or full disk after filling a large document.","solutions":["Read the inner error after the path in 'não gravei ...: ...' to identify io vs lopdf cause","Ensure the output directory exists (create_dir_all) and is writable before calling fill","Close any program holding the output file open, or choose a different output name/location","Check free disk space and file/directory permissions; retry after fixing"],"exampleFix":"// before\ndoc.save(&output).map_err(|e| anyhow!(\"não gravei {}: {}\", output.display(), e))?;\n// after\nif let Some(dir) = output.parent() { std::fs::create_dir_all(dir)?; }\nlet out = output.with_extension(\"new.pdf\");\ndoc.save(&out).map_err(|e| anyhow!(\"não gravei {}: {}\", out.display(), e))?;\nstd::fs::rename(&out, &output)?;","handlingStrategy":"try-catch","validationCode":"let dir = out_dir_for(opts)?;\nstd::fs::create_dir_all(&dir)?;\nlet probe = dir.join(\".write_test\");\nstd::fs::write(&probe, b\"\").map_err(|e| anyhow!(\"output dir not writable: {}\", e))?;\nlet _ = std::fs::remove_file(&probe);","typeGuard":null,"tryCatchPattern":"match fill(&opts, progress) {\n    Err(e) if e.to_string().starts_with(\"não gravei\") => {\n        eprintln!(\"save failed: {e}; check disk space, permissions, and that the file is not open elsewhere\");\n    }\n    Ok(result) => { /* use result.output */ }\n    Err(e) => return Err(e),\n}","preventionTips":["Create the output directory (create_dir_all) before saving","Write to a temp name then rename into place to avoid partial/locked outputs","Ask users to close the PDF viewer that may hold the output file open","Check free disk space and directory permissions when running as a service or in a sandbox"],"tags":["pdf","file-write","io"],"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"}