{"record":{"id":"27189a1dad57c9ae","repo":"plandex-ai/plandex","slug":"error-creating-directory-v-27189a","errorCode":null,"errorMessage":"error creating directory: %v","messagePattern":"error creating directory: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/model_settings.go","lineNumber":76,"sourceCode":"\t}\n\n\tcurrentHash, err := clientModelPackSchemaRoles.ToModelPackSchemaRoles().Hash()\n\tif err != nil {\n\t\treturn ModelSettingsCheckLocalChangesResult{}, fmt.Errorf(\"error hashing model pack: %v\", err)\n\t}\n\n\tmodelPackSchemaRoles := clientModelPackSchemaRoles.ToModelPackSchemaRoles()\n\n\treturn ModelSettingsCheckLocalChangesResult{\n\t\tHasLocalChanges:           currentHash != string(lastSavedHash),\n\t\tLocalModelPackSchemaRoles: &modelPackSchemaRoles,\n\t}, nil\n}\n\nfunc WriteModelSettingsFile(path string, originalSettings *shared.PlanSettings) error {\n\terr := os.MkdirAll(filepath.Dir(path), 0755)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating directory: %v\", err)\n\t}\n\n\tmodelPackSchemaRoles := originalSettings.GetModelPack().ToModelPackSchema().ModelPackSchemaRoles\n\n\tclientModelPackRoles := modelPackSchemaRoles.ToClientModelPackSchemaRoles()\n\n\tbytes, err := json.MarshalIndent(clientModelPackRoles, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshalling model pack: %v\", err)\n\t}\n\n\terr = os.WriteFile(path, bytes, 0644)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing JSON file: %v\", err)\n\t}\n\n\terr = SaveModelPackRolesHash(path, &modelPackSchemaRoles)\n\tif err != nil {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/model_settings.go#L58-L94","documentation":"WriteModelSettingsFile persists a plan's current model pack to model-settings.json. Before writing it calls os.MkdirAll on the parent directory (e.g. ~/.plandex/<planId>) and wraps any failure as 'error creating directory: %v'. The cause is the wrapped OS error, typically a permissions or path problem.","triggerScenarios":"Calling WriteModelSettingsFile (directly or via updateModelSettings / SaveLatestPlanModelSettingsIfNeeded) when the parent directory cannot be created: read-only HOME, HOME unset so fs.HomePlandexDir resolves to an invalid path, disk full, or a file already exists where the directory should be.","commonSituations":"Running the CLI in containers/CI with a read-only or missing $HOME; restricted sandbox permissions; a stray file named like the plan directory under ~/.plandex; SELinux/AppArmor blocking writes.","solutions":["Check the wrapped OS error (e.g. permission denied) and fix directory permissions: chmod/chown ~/.plandex or run with proper privileges","Verify HOME is set to a writable directory; override PLandex home if the fs package supports it","If a regular file exists at the target directory path, remove or rename it","Free disk space if the error is no-space-left-on-device"],"exampleFix":"// before\nmkdir: cannot create directory '/home/ci/.plandex/xyz': Permission denied\n// after\nexport HOME=/writable/dir\nchmod u+w \"$HOME\" && mkdir -p \"$HOME/.plandex\"","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(path)\nif info, err := os.Stat(dir); err != nil {\n    if os.IsNotExist(err) {\n        if err := os.MkdirAll(dir, 0o755); err != nil { return err }\n    } else { return err }\n} else if !info.IsDir() {\n    return fmt.Errorf(\"%s is a file, not a directory\", dir)\n}","typeGuard":null,"tryCatchPattern":"if err := lib.WriteModelSettingsFile(path, settings); err != nil {\n    if strings.Contains(err.Error(), \"error creating directory\") {\n        // check HOME writability/permissions, then retry\n    }\n    return err\n}","preventionTips":["Ensure HOME is set and writable before running the CLI","Pre-create ~/.plandex with correct ownership in CI images","Don't place files where the plan directory should be","Watch for read-only mounts or SELinux denials on the home dir"],"tags":["go","filesystem","permissions","directory"],"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-14T00:17:10.932Z"}