{"record":{"id":"659a5e525debe01d","repo":"facebook/flow","slug":"failed-to-write-codemod-output","errorCode":null,"errorMessage":"failed to write codemod output","messagePattern":"failed to write codemod output","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_codemods/src/utils/codemod_printer.rs","lineNumber":64,"sourceCode":"                strip_root.as_ref().map(|p| p.to_str().unwrap_or(\"\")),\n                file,\n            );\n            println!(\">>> {} (#changes: {})\", display_path, diff.len());\n            println!(\"{}\", source);\n        }\n        Some([]) | None => {}\n    }\n}\n\npub async fn print_ast_file_real(file: FileKey) -> Option<FileKey> {\n    let file_path = file.to_absolute();\n    let file_input = FileInput::FileName(file_path.clone());\n    let diff = diff_heaps_get_diff(&file);\n    match diff.as_deref() {\n        Some([_, ..]) => {\n            let diff = diff.as_ref().unwrap();\n            let source = replacement_printer::print_unsafe(diff, &file_input);\n            std::fs::write(&file_path, source).expect(\"failed to write codemod output\");\n            Some(file)\n        }\n        Some([]) | None => None,\n    }\n}\n\nconst MAX_FILES_OPEN: usize = 1024;\n\npub async fn print_asts(\n    strip_root: &Option<PathBuf>,\n    write: bool,\n    files: Vec<FileKey>,\n) -> Option<Vec<FileKey>> {\n    fn print_dry(strip_root: &Option<PathBuf>, mut files: Vec<FileKey>) -> Option<Vec<FileKey>> {\n        files.sort();\n        for file in &files {\n            print_ast_file_dry(strip_root, file);\n        }","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_codemods/src/utils/codemod_printer.rs#L46-L82","documentation":"After a codemod mutates a file's AST, `print_ast_file_real` re-prints the transformed source and writes it back over the original file via `std::fs::write(...).expect(\"failed to write codemod output\")`. The panic fires when that write fails: no write permission on the file, read-only filesystem or container mount, disk full or quota exceeded, or the path vanished/became invalid between parse and write.","triggerScenarios":"Running a codemod in write mode (`write=true`) on a checkout without write permission or owned by another uid; ENOSPC (disk full, inode exhaustion, quota); file deleted or its symlink target removed while the codemod was running; immutable-bit or ACL denying writes.","commonSituations":"CI sandboxes with read-only source mounts; Docker volume mounts with mismatched uid/gid; codemods run on a full disk; repos on NFS with stale handles; another process deleting files mid-run.","solutions":["Check writability of the failing file: `test -w path`; fix permissions (chmod/chown) or remount the volume read-write.","Check capacity: `df -h .` and `df -i .` for space/inode exhaustion, free space or raise quota, then re-run.","Re-run the codemod from a stable, unmodified checkout so files are not deleted mid-run.","If one specific file keeps failing, inspect it for symlink oddities or immutable attributes (`lsattr path`)."],"exampleFix":"// before\nstd::fs::write(&file_path, source).expect(\"failed to write codemod output\");\n\n// after\nif let Err(e) = std::fs::write(&file_path, source) {\n    eprintln!(\"skipping {}: cannot write codemod output ({e})\", file_path.display());\n    return None;\n}","handlingStrategy":"validation","validationCode":"// Ensure each codemod target is writable before running in write mode\nuse std::fs::OpenOptions;\nfn target_is_writable(p: &std::path::Path) -> bool {\n    if !p.is_file() { return false; }\n    OpenOptions::new().write(true).open(p).is_ok()\n}\nlet all_writable = files.iter().all(|f| target_is_writable(&f.to_absolute()));","typeGuard":null,"tryCatchPattern":"if let Err(e) = std::fs::write(&file_path, source) {\n    eprintln!(\"skipping {}: cannot write codemod output ({e})\", file_path.display());\n    continue;\n}","preventionTips":["Run codemods on writable checkouts; never in write mode against read-only CI mounts.","Check `df -h` / `df -i` before large rewrites.","Prevent other processes from deleting or locking target files during the run."],"tags":["filesystem","codemod","file-write","permissions"],"backgroundTag":"file-write-failed","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}