{"record":{"id":"8ae6a41db4601237","repo":"hashicorp/nomad","slug":"couldn-t-create-destination-directory-v-w","errorCode":null,"errorMessage":"Couldn't create destination directory %v: %w","messagePattern":"Couldn't create destination directory (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocdir/task_dir.go","lineNumber":242,"sourceCode":"\nfunc (t *TaskDir) embedDirs(entries map[string]string) error {\n\tsubdirs := make(map[string]string)\n\tfor source, dest := range entries {\n\t\tif t.skip.Contains(source) {\n\t\t\t// source in skip list\n\t\t\tcontinue\n\t\t}\n\n\t\t// Check to see if directory exists on host.\n\t\ts, err := os.Stat(source)\n\t\tif os.IsNotExist(err) {\n\t\t\tcontinue\n\t\t}\n\n\t\t// Embedding a single file\n\t\tif !s.IsDir() {\n\t\t\tif err := createDir(t.Dir, filepath.Dir(dest)); err != nil {\n\t\t\t\treturn fmt.Errorf(\"Couldn't create destination directory %v: %w\", dest, err)\n\t\t\t}\n\n\t\t\t// Copy the file.\n\t\t\ttaskEntry := filepath.Join(t.Dir, dest)\n\t\t\tuid, gid := getOwner(s)\n\t\t\tif err := linkOrCopy(source, taskEntry, uid, gid, s.Mode().Perm()); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tcontinue\n\t\t}\n\n\t\t// Create destination directory.\n\t\tdestDir := filepath.Join(t.Dir, dest)\n\n\t\tif err := createDir(t.Dir, dest); err != nil {\n\t\t\treturn fmt.Errorf(\"Couldn't create destination directory %v: %w\", destDir, err)\n\t\t}","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocdir/task_dir.go#L224-L260","documentation":"embedDirs, called from buildChroot, embeds host files into the chroot task directory. When a chroot mapping entry is a single file, it first creates the destination directory inside t.Dir via createDir. This error wraps createDir's failure, reported with the destination path. It aborts chroot construction for the alloc.","triggerScenarios":"TaskDir.buildChroot processing a chroot map entry whose source is a file, and createDir(t.Dir, filepath.Dir(dest)) fails — e.g. a non-directory exists at the parent path inside the task dir, or the task dir is unwritable.","commonSituations":"data_dir on a full/read-only disk; previous task run left a file where a chroot destination directory must be; chroot map entry with conflicting paths (same dest as both file and directory from config); permissions on the nomad data dir changed.","solutions":["Read the wrapped OS error: EEXIST/ENOTDIR → delete the conflicting file at the destination inside the task dir; ENOSPC → free disk space; EACCES → fix data_dir ownership","Clean the task dir for the failing alloc and restart it (`rm -rf <data_dir>/<alloc>/<task>` with client stopped)","Check the task's chroot mapping in the client config for duplicate/conflicting destination paths","Confirm the nomad user can write t.Dir"],"exampleFix":"# before\nCouldn't create destination directory etc/ssl/certs: mkdir /var/nomad/.../etc/ssl/certs: not a directory\n# after\n$ ls -ld /var/nomad/<alloc>/<task>/etc/ssl/certs  # it's a file\n$ rm /var/nomad/<alloc>/<task>/etc/ssl/certs\n$ nomad alloc restart <alloc>","handlingStrategy":"validation","validationCode":"// pre-check chroot destination inside task dir isn't occupied by a file\nfor _, dest := range chrootMap {\n    p := filepath.Join(taskDir, filepath.Dir(dest))\n    if fi, err := os.Stat(p); err == nil && !fi.IsDir() {\n        os.RemoveAll(p) // or fail fast with a clear message\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := taskDir.Build(fsi, chroot, username); err != nil {\n    var e *fmt.Errorf\n    if errors.As(err, &e) && strings.Contains(err.Error(), \"Couldn't create destination directory\") {\n        // inspect wrapped errno: ENOSPC → free space; ENOTDIR → clean task dir; then retry\n        return retryAfterClean(taskDir, err)\n    }\n    return err\n}","preventionTips":["Monitor data_dir free space","Don't map the same destination to both a file and a directory in chroot config","Reset the task dir when restarting an alloc after config changes","Keep data_dir owned by the nomad user"],"tags":["filesystem","chroot","permissions"],"backgroundTag":"mkdir-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}