tonhowtf/omniget · error
nao leu
Error message
nao leu {}: {} What it means
Document::open wraps std::fs::read failure with this message naming the PDF path and the io::Error. Before PDFium even sees the file, the whole PDF must be read into memory (PDFium reads from the buffer while the document is open), so any I/O failure aborts here. The inner error distinguishes NotFound, PermissionDenied, IsADirectory, etc.
Solutions
- Verify the path exists and is a regular file before opening (Path::is_file)
- Check file read permissions and request access (macOS sandbox: security-scoped bookmark)
- Re-prompt the user to re-select the file if it moved or was deleted
- Copy remote/network files locally before opening if the mount is unreliable
Example fix
// before
let doc_info = pdf::info(&path)?; // 'nao leu /x/arquivo.pdf: No such file'
// after
if !path.is_file() {
let picked = re_prompt_for_file()?;
return pdf::info(&picked);
}
let doc_info = pdf::info(&path)?; Defensive patterns
Strategy: try-catch
Validate before calling
fn readable_pdf_path(p: &std::path::Path) -> Result<(), String> {
if !p.is_file() { return Err(format!("arquivo não encontrado: {}", p.display())); }
std::fs::File::open(p).map(|_| ()).map_err(|e| format!("sem permissão de leitura em {}: {e}", p.display()))
} Try / catch
match pdf::info(&path) {
Err(e) if e.to_string().contains("nao leu ") => {
eprintln!("{e}\nConfirme que o arquivo existe e é acessível; selecione-o novamente.");
re_prompt_for_file()?;
}
other => other?,
} Prevention
- Re-check existence right before opening; files can move between pick and use
- Keep macOS security-scoped bookmarks for sandboxed file access
- Copy files from unstable mounts (network/USB) to a temp dir first
- Distinguish directories from files in file pickers
When it happens
Trigger: Calling any PDF operation with a path that does not exist, is unreadable (permissions), is a directory, or on a file that disappears/is locked mid-operation.
Common situations: User moved/renamed/deleted the PDF after picking it in a file dialog; opening files on a disconnected network drive or ejected USB; permission issues after the app gained file access only via a dialog; passing a folder path instead of a file.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Failed to move into place
- não gravei
- não consegui ler a lista
- Failed to read .torrent file
- Failed to read .torrent file
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/22a46c2f622e676e.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/pdf.rs:188
let leaked: &'static Api = Box::leak(Box::new(api));
*guard = Some(leaked);
Ok(leaked)
}
pub fn available() -> bool {
crate::core::pdfium::is_installed()
}
struct Document {
api: &'static Api,
doc: Doc,
// O PDFium lê da memória enquanto o documento estiver aberto.
_data: Vec<u8>,
}
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,View on GitHub (pinned to 8600b91f42)