dbt-labs/dbt-core · error · minijinja::Error (InvalidOperation)
Failed to create directory {}: {}
Error message
Failed to create directory {}: {} What it means
After clearing stale files on the parent chain, write_file calls fs::create_dir_all for the destination parent; if directory creation fails (permission denied, read-only filesystem, path component is a file, name too long), this error includes the full parent path and OS error.
Source
Thrown at crates/dbt-jinja-utils/src/phases/run/run_node_context.rs:758
if let Some(parent) = full_path.parent()
&& !parent.is_dir()
{
// Parent is missing, or a stale file on the parent chain (from an older
// layout) sits where we now need a directory. Remove the deepest such
// file so create_dir_all can rebuild the tree, then create it.
for ancestor in parent.ancestors() {
if ancestor.is_file() {
if let Err(e) = fs::remove_file(ancestor) {
return Err(Error::new(
ErrorKind::InvalidOperation,
format!("Failed to remove stale file {}: {}", ancestor.display(), e),
));
}
break;
}
}
if let Err(e) = fs::create_dir_all(parent) {
return Err(Error::new(
ErrorKind::InvalidOperation,
format!("Failed to create directory {}: {}", parent.display(), e),
));
}
}
// A stale directory sitting where we now write a flat file fails with EISDIR.
if full_path.is_dir()
&& let Err(e) = fs::remove_dir_all(full_path)
{
return Err(Error::new(
ErrorKind::InvalidOperation,
format!(
"Failed to remove stale directory {}: {}",
full_path.display(),
e
),
));View on GitHub (pinned to 0267ce9170)
Solutions
- Check the wrapped OS error: fix permissions (chmod/chown) or free disk space as indicated.
- If a path component is a plain file, remove it so create_dir_all can build the tree.
- Ensure the container/CI mount for target/ is writable.
- Verify no path component exceeds filesystem name-length limits.
Example fix
// before target/models # exists as a regular file, EACCES on mkdir // after rm target/models # remove stale file where a directory is needed
Defensive patterns
Strategy: try-catch
Try / catch
if let Err(e) = fs::create_dir_all(parent) {
if e.kind() == std::io::ErrorKind::PermissionDenied {
// hint: mkdir/chown the target tree for the running user
}
return Err(wrap(parent, e));
} Prevention
- Verify target/ is writable and on a writable filesystem before running in containers/CI.
- Ensure no regular file occupies a path component of the artifact tree (e.g. target/models).
- Set a dedicated --target-path per job when running parallel dbt jobs.
When it happens
Trigger: The nested artifact path's parent cannot be created: a parent component exists as a regular file, the filesystem is read-only or full, or the user lacks write permission on the target/ tree.
Common situations: Containers with read-only target/ mounts; a file named like an intended directory (e.g. target/models) from older layouts; disk quota exceeded in CI caches.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- Failed to remove stale file {}: {}
- Failed to remove stale directory {}: {}
- Failed to write file: {e}
- {type(df)} is not a supported type for dbt Python materializ
- {type(df)} is not a supported type for dbt Python materializ
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/76d9972e06680fff.
Report an issue: GitHub.