{"record":{"id":"17ba3350627d41f0","repo":"jdx/mise","slug":"managed-file-parent-does-not-exist","errorCode":null,"errorMessage":"managed file parent does not exist: {}","messagePattern":"managed file parent does not exist: (.+?)","errorType":"error_code","errorClass":"eyre::Report","httpStatus":null,"severity":"error","filePath":"src/system/managed_files.rs","lineNumber":1538,"sourceCode":"fn write_file(\n    path: &Path,\n    content: &[u8],\n    owner: Option<&str>,\n    group: Option<&str>,\n    mode: u32,\n    replace: bool,\n) -> Result<()> {\n    let parent = path\n        .parent()\n        .ok_or_else(|| eyre!(\"managed file has no parent: {}\", path.display()))?;\n    match fs::metadata(parent) {\n        Ok(metadata) if metadata.is_dir() => {}\n        Ok(_) => bail!(\n            \"managed file parent is not a directory: {}\",\n            parent.display()\n        ),\n        Err(error) if error.kind() == std::io::ErrorKind::NotFound => {\n            bail!(\"managed file parent does not exist: {}\", parent.display())\n        }\n        Err(error) => return Err(error.into()),\n    }\n    // Prepare the complete replacement before mutating the destination. In\n    // particular, a metadata permission error must leave the old path intact.\n    let mut temporary = tempfile::NamedTempFile::new_in(parent)?;\n    temporary.write_all(content)?;\n    set_metadata(temporary.path(), owner, group, mode)?;\n    temporary.as_file_mut().sync_all()?;\n    match fs::symlink_metadata(path) {\n        Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}\n        Err(error) => return Err(error.into()),\n        Ok(metadata) if metadata.file_type().is_file() => {}\n        Ok(_) if !replace => {\n            bail!(\"refusing to replace non-file path: {}\", path.display())\n        }\n        Ok(metadata) if metadata.file_type().is_dir() => {\n            fs::remove_dir(path).wrap_err_with(|| {","sourceCodeStart":1520,"sourceCodeEnd":1556,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/managed_files.rs#L1520-L1556","documentation":"While validating a managed file's destination, the library stats the parent directory. If the parent does not exist (`ErrorKind::NotFound`), it fails with this error instead of implicitly creating directories — managed file installation does not auto-create arbitrary parent trees.","triggerScenarios":"Calling a managed-file write/install whose parent directory has never been created — e.g. path \"/opt/myapp/config/app.conf\" where neither \"config\" nor \"myapp\" exists on disk.","commonSituations":"First-time deployment on a fresh machine where the app's config directories were never provisioned; typos in configured paths; container images missing expected directories.","solutions":["Create the parent directory first with `mkdir -p` / `fs::create_dir_all(parent)`","Check the configured path for typos (wrong directory name, missing mount point)","Ensure any volume/mount the path lives on is mounted before running the operation"],"exampleFix":"// before\ninstall_managed_file(Path::new(\"/opt/myapp/config/app.conf\"), ...)?; // /opt/myapp/config missing\n// after\nstd::fs::create_dir_all(\"/opt/myapp/config\")?;\ninstall_managed_file(Path::new(\"/opt/myapp/config/app.conf\"), ...)?;","handlingStrategy":"validation","validationCode":"fn ensure_parent_exists(path: &std::path::Path) -> std::io::Result<()> {\n    if let Some(parent) = path.parent() {\n        std::fs::create_dir_all(parent)?;\n    }\n    Ok(())\n}","typeGuard":"fn parent_exists(path: &std::path::Path) -> bool {\n    path.parent().map_or(false, |p| p.exists())\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"parent does not exist\") => {\n        std::fs::create_dir_all(expected_parent)?;\n        retry_operation()?;\n    }\n    other => other?,\n}","preventionTips":["Create the full directory tree during provisioning before managed-file writes","Check configured paths for typos early","Ensure mounts/volumes are up before running install steps"],"tags":["filesystem","path","missing-directory"],"backgroundTag":"directory-not-found","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}