{"record":{"id":"d94bd76542098e56","repo":"plandex-ai/plandex","slug":"error-creating-results-dir-v","errorCode":null,"errorMessage":"error creating results dir: %v","messagePattern":"error creating results dir: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/result_helpers.go","lineNumber":41,"sourceCode":"\tnow := time.Now()\n\tif result.Id == \"\" {\n\t\tresult.Id = uuid.New().String()\n\t\tresult.CreatedAt = now\n\t}\n\tresult.UpdatedAt = now\n\n\tbytes, err := json.MarshalIndent(result, \"\", \"  \")\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshalling result: %v\", err)\n\t}\n\n\tresultsDir := getPlanResultsDir(result.OrgId, result.PlanId)\n\n\terr = os.MkdirAll(resultsDir, 0755)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating results dir: %v\", err)\n\t}\n\n\tlog.Printf(\"Storing plan result: %s - %s\", result.Path, result.Id)\n\n\terr = os.WriteFile(filepath.Join(resultsDir, result.Id+\".json\"), bytes, 0644)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing result file: %v\", err)\n\t}\n\n\treturn nil\n\n}\n\ntype CurrentPlanStateParams struct {\n\tOrgId                    string\n\tPlanId                   string\n\tPlanFileResults          []*PlanFileResult","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/result_helpers.go#L23-L59","documentation":"StorePlanResult persists a PlanFileResult as JSON under the plan's results directory. Before writing the file it calls os.MkdirAll(resultsDir, 0755); if that fails (e.g. permissions, read-only filesystem, invalid path) it wraps the OS error with this message.","triggerScenarios":"Calling StorePlanResult with an OrgId/PlanId that resolves to a results dir path which cannot be created: parent directory not writable, disk full, results path is a file instead of a directory, or the org plan path contains invalid characters.","commonSituations":"Server running as a user without write permission on the plans data directory; DATA_DIR mounted read-only (container volume misconfig); corrupted org/plan IDs producing a bogus path; full disk on the host.","solutions":["Check the wrapped OS error (os.PathError) for the actual path and errno (EACCES/EROFS/ENOSPC/ENOTDIR)","Verify the process user has write access to the plans data root directory","Ensure the results path is not blocked by an existing regular file with the same name","Free disk space or remount the volume read-write","Validate OrgId/PlanId before calling so the derived path is sane"],"exampleFix":"// before\nif err := db.StorePlanResult(result); err != nil {\n\tlog.Printf(\"store failed: %v\", err)\n}\n// after\nif err := os.MkdirAll(filepath.Dir(getPlanResultsDir(orgId, planId)), 0755); err != nil {\n\treturn fmt.Errorf(\"data dir not writable: %w\", err)\n}\nif err := db.StorePlanResult(result); err != nil {\n\tlog.Printf(\"store failed: %v\", err)\n}","handlingStrategy":"validation","validationCode":"func canStoreResults(orgId, planId string) error {\n\tdir := getPlanResultsDir(orgId, planId)\n\tif err := os.MkdirAll(dir, 0755); err != nil {\n\t\treturn fmt.Errorf(\"results dir not creatable: %w\", err)\n\t}\n\tf, err := os.CreateTemp(dir, \".probe-*\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tf.Close()\n\tos.Remove(f.Name())\n\treturn nil\n}","typeGuard":"func isPathError(err error) *os.PathError {\n\tvar pe *os.PathError\n\tif errors.As(err, &pe) {\n\t\treturn pe\n\t}\n\treturn nil\n}","tryCatchPattern":"if err := db.StorePlanResult(result); err != nil {\n\tif pe := isPathError(err); pe != nil && errors.Is(pe.Err, syscall.EACCES) {\n\t\treturn fmt.Errorf(\"fix permissions on %s: %w\", pe.Path, err)\n\t}\n\treturn err\n}","preventionTips":["Pre-create and chown the plans data root at deployment time","Run the server as a user that owns the data volume","Monitor free disk space with alerts before it hits zero","Validate org/plan IDs before deriving filesystem paths","Keep data volumes mounted read-write; fail fast at startup if read-only"],"tags":["go","filesystem","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"}