{"record":{"id":"9fe31e17fa8db6de","repo":"tonhowtf/omniget","slug":"n-o-gravei-o-xlsx","errorCode":null,"errorMessage":"não gravei o xlsx: {}","messagePattern":"não gravei o xlsx: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf_table.rs","lineNumber":417,"sourceCode":"            .take(31)\n            .collect();\n        sheet.set_name(&name)?;\n        for (r, row) in t.cells.iter().enumerate() {\n            for (c, cell) in row.iter().enumerate() {\n                let (r, c) = (r as u32, c as u16);\n                match as_number(cell) {\n                    Some(v) => {\n                        sheet.write_number(r, c, v)?;\n                    }\n                    None => {\n                        sheet.write_string(r, c, cell.trim())?;\n                    }\n                }\n            }\n        }\n    }\n    book.save(path)\n        .map_err(|e| anyhow!(\"não gravei o xlsx: {}\", e))?;\n    Ok(())\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n    use crate::core::tools::pdf::TextChar;\n\n    fn ch(c: char, x: f32, y: f32, size: f32) -> TextChar {\n        TextChar {\n            ch: c,\n            x0: x,\n            x1: x + size * 0.5,\n            y0: y,\n            y1: y + size,\n            size,\n            mono: false,\n            bold: false,","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf_table.rs#L399-L435","documentation":"Wraps the umya-spreadsheet `book.save(path)` failure when persisting the generated XLSX workbook. The original save error (io or zip-related) is embedded in the message. It fires only at the final write step — table extraction itself already succeeded.","triggerScenarios":"The destination path is in a read-only or nonexistent directory; insufficient write permission; path is a directory, not a file; path length/format issues (invalid chars on Windows); disk full; another process holds a lock on the target .xlsx (e.g. open in Excel).","commonSituations":"Target .xlsx is currently open in Excel/LibreOffice (Windows file lock); output_dir points to a non-writable location; saving to a network share that dropped; filename contains characters the OS rejects.","solutions":["Check the embedded cause in the message; if permission/locked, close the file in Excel/LibreOffice or pick another output path","Verify the output directory exists and is writable (create_dir_all / check permissions)","Save to a temp file then atomically rename, so partial writes don't corrupt the target","Confirm disk space and that the path is a valid file path, not a directory"],"exampleFix":"// before\nwrite_xlsx(&book, &Path::new(\"C:\\\\relatorio.xlsx\"))?;\n// after\nlet target = Path::new(\"C:\\\\relatorio.xlsx\");\nif target.exists() && !fs::remove_file(target).map(|_| true).or_else(|e| e.kind()==NotFound).unwrap_or(false) {\n    anyhow::bail!(\"feche o arquivo no Excel antes de sobrescrever\");\n}\nlet tmp = target.with_extension(\"xlsx.tmp\");\nwrite_xlsx(&book, &tmp)?;\nfs::rename(&tmp, target)?;","handlingStrategy":"try-catch","validationCode":"// Rust: ensure the destination is writable before extraction\nfn ensure_writable_target(path: &std::path::Path) -> anyhow::Result<()> {\n    if let Some(dir) = path.parent() { std::fs::create_dir_all(dir)?; }\n    if path.exists() {\n        std::fs::OpenOptions::new().append(true).open(path)\n            .map_err(|e| anyhow!(\"alvo bloqueado/sem permissão: {}\", e))?;\n    }\n    Ok(())\n}","typeGuard":"fn target_writable(path: &std::path::Path) -> bool {\n    path.extension().map(|e| e == \"xlsx\").unwrap_or(false)\n        && path.parent().map(|d| d.is_dir()).unwrap_or(true)\n        && std::fs::OpenOptions::new().write(true).create(true).open(path).is_ok()\n}","tryCatchPattern":"match write_xlsx(&book, &path) {\n    Err(e) if e.to_string().contains(\"não gravei o xlsx\") => {\n        let tmp = path.with_extension(\"xlsx.tmp\");\n        write_xlsx(&book, &tmp)?;              // retry via temp file\n        std::fs::rename(&tmp, &path)?;\n    }\n    other => other?,\n}","preventionTips":["Write to a temp file and rename, avoiding corrupt/locked targets","Check the .xlsx isn't open in Excel/LibreOffice before overwriting on Windows","create_dir_all the output directory and test writability up front","Catch the error early in long batch jobs and continue with remaining files instead of aborting"],"tags":["rust","file-write","xlsx","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"}