{"record":{"id":"76d9972e06680fff","repo":"dbt-labs/dbt-core","slug":"failed-to-create-directory","errorCode":null,"errorMessage":"Failed to create directory {}: {}","messagePattern":"Failed to create directory (.+?): (.+?)","errorType":"exception","errorClass":"minijinja::Error (InvalidOperation)","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-utils/src/phases/run/run_node_context.rs","lineNumber":758,"sourceCode":"    if let Some(parent) = full_path.parent()\n        && !parent.is_dir()\n    {\n        // Parent is missing, or a stale file on the parent chain (from an older\n        // layout) sits where we now need a directory. Remove the deepest such\n        // file so create_dir_all can rebuild the tree, then create it.\n        for ancestor in parent.ancestors() {\n            if ancestor.is_file() {\n                if let Err(e) = fs::remove_file(ancestor) {\n                    return Err(Error::new(\n                        ErrorKind::InvalidOperation,\n                        format!(\"Failed to remove stale file {}: {}\", ancestor.display(), e),\n                    ));\n                }\n                break;\n            }\n        }\n        if let Err(e) = fs::create_dir_all(parent) {\n            return Err(Error::new(\n                ErrorKind::InvalidOperation,\n                format!(\"Failed to create directory {}: {}\", parent.display(), e),\n            ));\n        }\n    }\n\n    // A stale directory sitting where we now write a flat file fails with EISDIR.\n    if full_path.is_dir()\n        && let Err(e) = fs::remove_dir_all(full_path)\n    {\n        return Err(Error::new(\n            ErrorKind::InvalidOperation,\n            format!(\n                \"Failed to remove stale directory {}: {}\",\n                full_path.display(),\n                e\n            ),\n        ));","sourceCodeStart":740,"sourceCodeEnd":776,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-utils/src/phases/run/run_node_context.rs#L740-L776","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ntarget/models  # exists as a regular file, EACCES on mkdir\n// after\nrm target/models  # remove stale file where a directory is needed","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = fs::create_dir_all(parent) {\n    if e.kind() == std::io::ErrorKind::PermissionDenied {\n        // hint: mkdir/chown the target tree for the running user\n    }\n    return Err(wrap(parent, e));\n}","preventionTips":["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."],"tags":["filesystem","mkdir","permissions","dbt"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}