tonhowtf/omniget · error
{}: {}
Error message
{}: {} What it means
After FPDF_LoadMemDocument64 returns a null document, Document::open maps FPDF_GetLastError codes to friendly strings (3 = not a valid PDF, 4 = wrong/missing password, 5 = unsupported security scheme, 6 = invalid page) and returns 'path: why'. This means the bytes were read fine but PDFium rejected the document itself — not an I/O problem.
Solutions
- Ask the user for the password and retry open with Some(password) when the reason is 'senha incorreta ou ausente'
- Verify the file is actually a PDF (check %PDF- header) before calling and reject non-PDFs earlier
- Recover/redownload truncated or corrupted PDFs (try a PDF repair step)
- For unsupported security schemes, decrypt with another tool or use a PDFium build with more encryption support
Example fix
// before
let doc = pdf::open(&path, None)?; // 'arquivo.pdf: senha incorreta ou ausente'
// after
let doc = match pdf::open(&path, None) {
Err(e) if e.to_string().contains("senha") => {
let pw = prompt_password()?;
pdf::open(&path, Some(&pw))?
}
r => r?,
}; Defensive patterns
Strategy: try-catch
Validate before calling
fn looks_like_pdf(p: &std::path::Path) -> bool {
use std::io::Read;
std::fs::File::open(p).ok()
.and_then(|mut f| {
let mut h = [0u8; 5];
f.read_exact(&mut h).ok()?;
Some(&h == b"%PDF-")
})
.unwrap_or(false)
} Try / catch
match pdf::open(&path, password.as_deref()) {
Err(e) if e.to_string().contains("senha incorreta") => pdf::open(&path, Some(ask_password()?.as_str())),
Err(e) if e.to_string().contains("nao e um PDF valido") => { eprintln!("{e}"); Err(e) }
other => other,
} Prevention
- Validate the %PDF- header before attempting to open
- Detect encryption upfront and prompt for a password when needed
- Verify download integrity (size/checksum) for PDFs fetched over the network
- Warn users that DRM/unsupported security schemes cannot be opened by PDFium
When it happens
Trigger: Opening a file that is not a PDF (or corrupt/truncated PDF, code 3); opening an encrypted PDF without a password or with the wrong one (4); a PDF using an unsupported encryption/security handler (5).
Common situations: User renames a .docx/.jpg to .pdf; download interrupted leaving a truncated PDF; opening password-protected PDFs without supplying the password; enterprise DRM/encrypted PDFs PDFium cannot handle.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- could not determine app data dir
- source not a file
- nenhuma imagem
- PDFium sem
- PDFium nao esta instalado (Ajustes → Dependencias → PDFium)
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/eeace19c8acd051c.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/pdf.rs:202
}
impl Document {
fn open(api: &'static Api, path: &Path, password: Option<&str>) -> anyhow::Result<Self> {
let data = std::fs::read(path).map_err(|e| anyhow!("nao leu {}: {}", path.display(), e))?;
let pw = CString::new(password.unwrap_or("")).unwrap_or_default();
let doc =
unsafe { (api.load_mem)(data.as_ptr() as *const c_void, data.len(), pw.as_ptr()) };
if doc.is_null() {
let code = unsafe { (api.last_error)() };
let why = match code {
2 => "arquivo nao encontrado ou ilegivel",
3 => "nao e um PDF valido",
4 => "senha incorreta ou ausente",
5 => "esquema de seguranca nao suportado",
6 => "pagina invalida",
_ => "erro desconhecido",
};
return Err(anyhow!("{}: {}", path.display(), why));
}
Ok(Document {
api,
doc,
_data: data,
})
}
fn new(api: &'static Api) -> anyhow::Result<Self> {
let doc = unsafe { (api.new_doc)() };
if doc.is_null() {
return Err(anyhow!("nao criou o documento"));
}
Ok(Document {
api,
doc,
_data: Vec::new(),
})View on GitHub (pinned to 8600b91f42)