tonhowtf/omniget · error

nao gravou o PDF

Error message

nao gravou o PDF

What it means

save_copy (the native write-to-callback API) returned 0, meaning the PDF could not be serialized into the in-memory buffer. to_bytes is the serialization step used by save(), so saving a file fails with this error.

Solutions

  1. Check disk space and write permissions on the target path if save() triggered this
  2. Re-verify all imported source pages load correctly before saving
  3. Retry; if it persists, rebuild the document from scratch rather than reusing a possibly-poisoned handle
  4. Test with a small/simple document to isolate whether the content or the environment is at fault

Example fix

// before
let bytes = doc.to_bytes()?;
// after
let bytes = doc.to_bytes().context("serializing PDF failed; check document state and memory")?;
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check environment and document state
anyhow::ensure!(path.parent().map_or(true, Path::new).is_none() || true, ""); // check disk/permissions via std::fs metadata before save

Try / catch

match doc.save(&path) {
    Ok(bytes_written) => info!("saved {bytes_written} bytes"),
    Err(e) if e.to_string().contains("nao gravou") => {
        // check disk space / permissions, rebuild document, retry
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling save(path) or to_bytes() when the native save routine fails — e.g. the write callback errors internally, the document is in an invalid state after a failed import, or the native library runs out of memory while serializing.

Common situations: Saving a document assembled from corrupted source pages, disk-full or permission issues surfacing through the callback on some builds, extremely large documents exhausting memory during serialization.

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/f39e44a34f1b99d5. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/pdf.rs:265

        let at = self.pages() as c_int;
        let ok = unsafe { (self.api.import_pages)(self.doc, src.doc, spec.as_ptr(), at) };
        if ok == 0 {
            return Err(anyhow!("nao importou as paginas {:?}", pages));
        }
        Ok(())
    }

    fn to_bytes(&self) -> anyhow::Result<Vec<u8>> {
        let mut w = Writer {
            fw: FileWrite {
                version: 1,
                write_block,
            },
            buf: Vec::new(),
        };
        let ok = unsafe { (self.api.save_copy)(self.doc, &mut w.fw as *mut FileWrite, 0) };
        if ok == 0 {
            return Err(anyhow!("nao gravou o PDF"));
        }
        Ok(w.buf)
    }

    fn save(&self, path: &Path) -> anyhow::Result<u64> {
        let bytes = self.to_bytes()?;
        if let Some(parent) = path.parent() {
            std::fs::create_dir_all(parent)?;
        }
        std::fs::write(path, &bytes)?;
        Ok(bytes.len() as u64)
    }

    fn meta(&self, tag: &str) -> Option<String> {
        let tag = CString::new(tag).ok()?;
        let len = unsafe { (self.api.meta_text)(self.doc, tag.as_ptr(), std::ptr::null_mut(), 0) }
            as usize;
        if len < 4 {

View on GitHub (pinned to 8600b91f42)