{"record":{"id":"c1d6dfe0d9523809","repo":"plandex-ai/plandex","slug":"error-creating-applies-dir-v","errorCode":null,"errorMessage":"error creating applies dir: %v","messagePattern":"error creating applies dir: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/result_helpers.go","lineNumber":752,"sourceCode":"\tfor _, desc := range convoMessageDescriptions {\n\t\tdescriptionIds = append(descriptionIds, desc.Id)\n\t\tmessageIds = append(messageIds, desc.ConvoMessageId)\n\t}\n\n\tplanApply.PlanFileResultIds = resultIds\n\tplanApply.ConvoMessageDescriptionIds = descriptionIds\n\tplanApply.ConvoMessageIds = messageIds\n\n\t// Store the PlanApply object\n\tbytes, err := json.MarshalIndent(planApply, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshalling plan apply: %v\", err)\n\t}\n\n\tappliesDir := getPlanAppliesDir(orgId, planId)\n\terr = os.MkdirAll(appliesDir, 0755)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating applies dir: %v\", err)\n\t}\n\n\terr = os.WriteFile(filepath.Join(appliesDir, planApply.Id+\".json\"), bytes, 0644)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing plan apply file: %v\", err)\n\t}\n\n\tmsg := \"✅ Marked pending results as applied\"\n\n\tcurrentFiles := currentPlanState.CurrentPlanFiles.Files\n\tvar sortedFiles []string\n\tfor path := range currentFiles {\n\t\tsortedFiles = append(sortedFiles, path)\n\t}\n\tsort.Strings(sortedFiles)\n\tfor _, path := range sortedFiles {\n\t\tmsg += fmt.Sprintf(\"\\n • 📄 %s\", path)\n\t}","sourceCodeStart":734,"sourceCodeEnd":770,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/result_helpers.go#L734-L770","documentation":"ApplyPlan persists a PlanApply record as JSON under the plan's applies directory. Before writing the file it calls os.MkdirAll(appliesDir, 0755); if the directory cannot be created the underlying OS error is wrapped with this message. The library throws it because it cannot store the apply record without the directory existing.","triggerScenarios":"os.MkdirAll fails inside ApplyPlan — e.g. the parent org/plan directory path contains a file where a directory is expected, the process lacks write permission on the data root, the disk is full, or the path exceeds filesystem length limits.","commonSituations":"Read-only mounts or containers running as non-root without ownership of the app data dir; a stale file (not dir) named like the applies dir; SELinux/AppArmor blocking writes; disk quota exceeded on the volume holding plan data.","solutions":["Check permissions/ownership on the plan data root (getPlanAppliesDir target) and grant the process write access","Verify the path segment where the applies dir belongs is a directory, not a regular file; remove/rename the conflicting file","Check disk space/quota (df -h, quota reports) on the volume","Inspect the wrapped %v cause (EACCES vs ENOSPC vs ENOTDIR) and fix accordingly"],"exampleFix":"// before: blindly writing into a path that may be a file\nappliesDir := getPlanAppliesDir(orgId, planId)\nerr = os.MkdirAll(appliesDir, 0755)\n// after: detect a file blocking the dir and recreate\nif fi, statErr := os.Stat(appliesDir); statErr == nil && !fi.IsDir() {\n    if rmErr := os.Remove(appliesDir); rmErr != nil {\n        return fmt.Errorf(\"applies path is a file and cannot be removed: %v\", rmErr)\n    }\n}\nerr = os.MkdirAll(appliesDir, 0755)","handlingStrategy":"validation","validationCode":"appliesDir := getPlanAppliesDir(orgId, planId)\nif fi, err := os.Stat(filepath.Dir(appliesDir)); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"applies parent path invalid: %v\", err)\n}\nif err := unix.Access(filepath.Dir(appliesDir), unix.W_OK); err != nil {\n    return fmt.Errorf(\"no write access to %s: %v\", filepath.Dir(appliesDir), err)\n}","typeGuard":null,"tryCatchPattern":"if err := os.MkdirAll(appliesDir, 0755); err != nil {\n    var pathErr *os.PathError\n    if errors.As(err, &pathErr) {\n        log.Printf(\"mkdir failed op=%s path=%s: %v\", pathErr.Op, pathErr.Path, pathErr.Err)\n    }\n    return fmt.Errorf(\"error creating applies dir: %v\", err)\n}","preventionTips":["Ensure the app's data root is writable by the process user at deploy time","Health-check disk space and inode usage before bulk operations","Never place regular files where the org/plan directory tree is expected","Include the wrapped os.PathError details in logs for faster diagnosis"],"tags":["filesystem","go","permissions","io"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}