{"record":{"id":"fccb87b845a87a3a","repo":"nikivdev/code","slug":"failed-to-persist","errorCode":null,"errorMessage":"failed to persist {}: {}","messagePattern":"failed to persist (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/flow_config.rs","lineNumber":788,"sourceCode":"    }\n\n    Ok(artifacts)\n}\n\nfn write_atomic(path: &Path, content: &str) -> Result<()> {\n    if let Some(parent) = path.parent() {\n        ensure_dir(parent)?;\n    }\n    let dir = path\n        .parent()\n        .map(PathBuf::from)\n        .unwrap_or_else(|| PathBuf::from(\".\"));\n    let mut temp = NamedTempFile::new_in(&dir)\n        .with_context(|| format!(\"failed to stage {}\", path.display()))?;\n    temp.write_all(content.as_bytes())\n        .with_context(|| format!(\"failed to write {}\", path.display()))?;\n    temp.persist(path)\n        .map_err(|err| anyhow::anyhow!(\"failed to persist {}: {}\", path.display(), err.error))?;\n    Ok(())\n}\n\nfn prune_empty_generated_parents(mut current: Option<&Path>, root: &Path) -> Result<()> {\n    while let Some(path) = current {\n        if path == root || !path.starts_with(root) || !path.exists() {\n            break;\n        }\n        let is_empty = fs::read_dir(path)\n            .with_context(|| format!(\"failed to read {}\", path.display()))?\n            .next()\n            .is_none();\n        if !is_empty {\n            break;\n        }\n        fs::remove_dir(path).with_context(|| format!(\"failed to remove {}\", path.display()))?;\n        current = path.parent();\n    }","sourceCodeStart":770,"sourceCodeEnd":806,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/flow_config.rs#L770-L806","documentation":"This error comes from temp.persist(path) in a stage-write-persist helper in flow_config.rs: a NamedTempFile is written then atomically renamed onto the destination path, and the persist step failed. persist fails when the rename(2) syscall fails, typically because the temp file and destination are on different filesystems or the destination is locked/blocked.","triggerScenarios":"Calling the persist helper (used when writing flow config/generated files) where temp.persist() cannot rename the temp file onto `path` — e.g. path is on another mount, target is a directory, or the OS refuses the replace.","commonSituations":"Config path pointing at a directory, cross-device temp dir vs config dir, destination opened by another process (Windows file locking), or permissions changed between staging and persist.","solutions":["Ensure the destination path is a file path, not an existing directory","Configure the temp file to be created in the same directory as the destination (the code already tries PathBuf::from(\".\") / path parent — verify the parent resolves correctly)","Close processes holding the destination file open (editors, sync tools) and retry","Check write/execute permissions on the destination directory"],"exampleFix":"// before\nlet dir = path.parent().map(Path::to_path_buf).unwrap_or_else(|| PathBuf::from(\".\"));\nlet mut temp = NamedTempFile::new_in(&dir)?;\n// after\nlet dir = path.parent().map(Path::to_path_buf).unwrap_or_else(|| PathBuf::from(\".\"));\nfs::create_dir_all(&dir)?; // ensure parent exists on same fs\nlet mut temp = NamedTempFile::new_in(&dir)?;","handlingStrategy":"try-catch","validationCode":"let p = std::path::Path::new(dest);\nif p.is_dir() { anyhow::bail!(\"{} is a directory, expected a file path\", p.display()); }\nif let Some(parent) = p.parent() { std::fs::create_dir_all(parent)?; }","typeGuard":null,"tryCatchPattern":"if let Err(e) = write_config_atomic(path, content) {\n    if e.to_string().contains(\"failed to persist\") {\n        // fall back to non-atomic write\n        std::fs::write(path, content)?;\n    } else { return Err(e); }\n}","preventionTips":["Always persist temp files into the destination's own directory (same filesystem)","Never point config paths at directories","Close editors/sync tools that hold locks on generated files"],"tags":["filesystem","io","atomic-write"],"backgroundTag":"file-persist-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}