tonhowtf/omniget · error
não gravei
Error message
não gravei {}: {} What it means
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.
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
Example fix
// before
doc.save(&output).map_err(|e| anyhow!("não gravei {}: {}", output.display(), e))?;
// after
if let Some(dir) = output.parent() { std::fs::create_dir_all(dir)?; }
let out = output.with_extension("new.pdf");
doc.save(&out).map_err(|e| anyhow!("não gravei {}: {}", out.display(), e))?;
std::fs::rename(&out, &output)?; Defensive patterns
Strategy: try-catch
Validate before calling
let dir = out_dir_for(opts)?;
std::fs::create_dir_all(&dir)?;
let probe = dir.join(".write_test");
std::fs::write(&probe, b"").map_err(|e| anyhow!("output dir not writable: {}", e))?;
let _ = std::fs::remove_file(&probe); Try / catch
match fill(&opts, progress) {
Err(e) if e.to_string().starts_with("não gravei") => {
eprintln!("save failed: {e}; check disk space, permissions, and that the file is not open elsewhere");
}
Ok(result) => { /* use result.output */ }
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/b544302aee54259d.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/pdf_form.rs:695
// O leitor tem que redesenhar a aparência com o valor novo.
if let Ok(root) = doc.catalog_mut() {
if let Ok(Object::Reference(r)) = root.get(b"AcroForm").cloned() {
if let Ok(Object::Dictionary(form)) = doc.get_object_mut(r) {
form.set("NeedAppearances", Object::Boolean(true));
}
} else if let Ok(Object::Dictionary(form)) = doc.catalog_mut()?.get_mut(b"AcroForm") {
form.set("NeedAppearances", Object::Boolean(true));
}
}
if opts.flatten {
flatten(&mut doc, &stamps, opts.font_size)?;
}
let output = out_path(opts)?;
doc.save(&output)
.map_err(|e| anyhow!("não gravei {}: {}", output.display(), e))?;
super::report(progress, ID, "done", total, Some(total), None);
Ok(FillResult {
input: opts.input.clone(),
output: output.to_string_lossy().to_string(),
fields: known.len(),
filled,
flattened: opts.flatten,
missing,
})
}
/// Desenha os valores nas páginas e apaga o formulário inteiro.
fn flatten(
doc: &mut Document,
stamps: &[(usize, [f32; 4], String, bool)],
font_size: f32,
) -> anyhow::Result<()> {
let ids: Vec<(u32, ObjectId)> = doc.get_pages().into_iter().collect();View on GitHub (pinned to 8600b91f42)