jdx/mise · error · eyre::Report
managed file parent is not a directory
Error message
managed file parent is not a directory: {} What it means
Before atomically replacing a managed file, the library validates the destination's parent directory. This error fires when the parent path exists and `fs::metadata` succeeds, but the metadata is not a directory — e.g. the parent is a regular file, symlink to a file, or other non-directory entry. The library refuses to proceed because it cannot create a temporary file inside a non-directory.
Solutions
- Inspect the parent path (`ls -la <parent>`) and remove or rename the non-directory entry if it is stale
- Correct the configured managed-file path so the parent component is an actual directory
- Create the intended directory structure manually before re-running
Example fix
// before
install_managed_file(Path::new("/etc/nginx.conf/conf.d/app.conf"), ...); // /etc/nginx.conf is a file
// after
fs::create_dir_all("/etc/nginx/conf.d")?;
install_managed_file(Path::new("/etc/nginx/conf.d/app.conf"), ...); Defensive patterns
Strategy: validation
Validate before calling
fn validate_parent_is_dir(path: &std::path::Path) -> Result<(), String> {
let parent = path.parent().ok_or("no parent")?;
match std::fs::metadata(parent) {
Ok(m) if m.is_dir() => Ok(()),
Ok(_) => Err(format!("{} is not a directory", parent.display())),
Err(e) => Err(e.to_string()),
}
} Type guard
fn parent_is_dir(path: &std::path::Path) -> bool {
path.parent().map_or(false, |p| std::fs::metadata(p).map_or(false, |m| m.is_dir()))
} Try / catch
match result {
Err(e) if e.to_string().contains("parent is not a directory") => {
eprintln!("fix path config: parent exists but is a file");
}
other => other?,
} Prevention
- Validate configured paths at startup, not at write time
- Never reuse a filename as a directory component
- Add pre-flight checks in deployment scripts (test -d "$parent")
When it happens
Trigger: Calling a managed-file write/install with a path whose parent exists but is a plain file — e.g. path "/etc/somefile/config.txt" where "/etc/somefile" is a file, or a config value where a filename was given where a directory was intended.
Common situations: Config mistakes where the managed path embeds a filename that actually exists as a file; a previous write created the parent as a file; leftover artifacts from a prior tool version.
Related errors
- invalid managed directory path
- local plugin directory does not exist
- local plugin source is not a directory
- managed file parent does not exist
- refusing to remove directory as a file
AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17).
Data as JSON: /api/errors/843ba1d9e975218d.
Report an issue: GitHub.
Appendix: source
Thrown at src/system/managed_files.rs:1533
_mode: u32,
) -> Result<()> {
bail!("managed system files are only supported on Unix")
}
fn write_file(
path: &Path,
content: &[u8],
owner: Option<&str>,
group: Option<&str>,
mode: u32,
replace: bool,
) -> Result<()> {
let parent = path
.parent()
.ok_or_else(|| eyre!("managed file has no parent: {}", path.display()))?;
match fs::metadata(parent) {
Ok(metadata) if metadata.is_dir() => {}
Ok(_) => bail!(
"managed file parent is not a directory: {}",
parent.display()
),
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
bail!("managed file parent does not exist: {}", parent.display())
}
Err(error) => return Err(error.into()),
}
// Prepare the complete replacement before mutating the destination. In
// particular, a metadata permission error must leave the old path intact.
let mut temporary = tempfile::NamedTempFile::new_in(parent)?;
temporary.write_all(content)?;
set_metadata(temporary.path(), owner, group, mode)?;
temporary.as_file_mut().sync_all()?;
match fs::symlink_metadata(path) {
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
Err(error) => return Err(error.into()),
Ok(metadata) if metadata.file_type().is_file() => {}View on GitHub (pinned to 533346cc37)