{"record":{"id":"c4b2eb127cbee7c3","repo":"plandex-ai/plandex","slug":"failed-to-create-directory-s-s","errorCode":null,"errorMessage":"failed to create directory %s: %s","messagePattern":"failed to create directory (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/apply.go","lineNumber":682,"sourceCode":"\t\t\t\tif string(bytes) == content {\n\t\t\t\t\t// log.Println(\"File is unchanged, skipping\")\n\t\t\t\t\terrCh <- nil\n\t\t\t\t\treturn\n\t\t\t\t} else {\n\t\t\t\t\tmu.Lock()\n\t\t\t\t\tupdatedFiles = append(updatedFiles, path)\n\t\t\t\t\ttoRevert[dstPath] = types.ApplyReversion{Content: string(bytes), Mode: mode}\n\t\t\t\t\tmu.Unlock()\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tmu.Lock()\n\t\t\t\tupdatedFiles = append(updatedFiles, path)\n\t\t\t\ttoRemoveOnRollback = append(toRemoveOnRollback, dstPath)\n\t\t\t\tmu.Unlock()\n\t\t\t\t// Create the directory if it doesn't exist\n\t\t\t\terr := os.MkdirAll(filepath.Dir(dstPath), 0755)\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCh <- fmt.Errorf(\"failed to create directory %s: %s\", filepath.Dir(dstPath), err.Error())\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Write the file\n\t\t\terr = os.WriteFile(dstPath, []byte(content), 0644)\n\t\t\tif err != nil {\n\t\t\t\terrCh <- fmt.Errorf(\"failed to write %s: %s\", dstPath, err.Error())\n\t\t\t\treturn\n\t\t\t}\n\t\t\terrCh <- nil\n\t\t}(path, content)\n\t}\n\n\tfor path, remove := range toRemove {\n\t\tgo func(path string, remove bool) {\n\t\t\tif !remove {\n\t\t\t\terrCh <- nil\n\t\t\t\treturn","sourceCodeStart":664,"sourceCodeEnd":700,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/apply.go#L664-L700","documentation":"During plan apply, os.MkdirAll fails to create the parent directory of a file being written (dstPath). Typically a permission problem or a path component that exists as a non-directory (e.g. a file where a folder is expected).","triggerScenarios":"os.MkdirAll(filepath.Dir(dstPath), 0755) fails — parent path component is a regular file, permission denied, or filesystem is full/read-only.","commonSituations":"Plan adds a file under a path where an existing file occupies a directory name (e.g. 'main.go' exists, plan writes 'main.go/util.go'); read-only checkout; disk quota exceeded; writing into a mounted volume without permissions.","solutions":["Remove/rename any regular file that occupies a directory position in the target path","Check disk space (df -h) and quota","Fix permissions on the parent directory (chmod/chown) or run from the correct project root","Ensure the filesystem is mounted read-write"],"exampleFix":"// before\n$ ls -l src   # src/templates is a FILE, plan adds src/templates/base.html\n// after\n$ mv src/templates src.tmplbak && mkdir src/templates\n$ plandex apply","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(dstPath)\nif info, err := os.Stat(dir); err == nil && !info.IsDir() {\n  return fmt.Errorf(\"%s exists as a file; a directory is required\", dir)\n}\nif err := os.MkdirAll(dir, 0o755); err != nil {\n  return fmt.Errorf(\"cannot create %s: %w\", dir, err)\n}","typeGuard":"func dirCreatable(dirPath string) bool {\n  if info, err := os.Stat(dirPath); err == nil { return info.IsDir() }\n  // walk up to find first existing ancestor; it must be a writable dir\n  parent := filepath.Dir(dirPath)\n  info, err := os.Stat(parent)\n  return err == nil && info.IsDir() && info.Mode().Perm()&0o200 != 0\n}","tryCatchPattern":"if err := os.MkdirAll(filepath.Dir(dstPath), 0o755); err != nil {\n  return fmt.Errorf(\"mkdir %s: %w\", filepath.Dir(dstPath), err)\n}","preventionTips":["Free disk space / check quota before large applies","Ensure volumes are mounted read-write","Remove files occupying directory positions in new-file paths","Run as a user with write access to the project root"],"tags":["go","filesystem","mkdir"],"backgroundTag":"mkdir-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}