{"record":{"id":"6b4ebd002d00743e","repo":"plandex-ai/plandex","slug":"error-creating-directory-v","errorCode":null,"errorMessage":"error creating directory: %v","messagePattern":"error creating directory: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/custom_models.go","lineNumber":138,"sourceCode":"\tif err != nil && !os.IsNotExist(err) {\n\t\treturn CustomModelsCheckLocalChangesResult{}, fmt.Errorf(\"error reading hash file: %v\", err)\n\t}\n\n\tcurrentHash, err := localModelsInput.Hash()\n\tif err != nil {\n\t\treturn CustomModelsCheckLocalChangesResult{}, fmt.Errorf(\"error hashing models: %v\", err)\n\t}\n\n\treturn CustomModelsCheckLocalChangesResult{\n\t\tHasLocalChanges:  currentHash != string(lastSavedHash),\n\t\tLocalModelsInput: localModelsInput,\n\t}, nil\n}\n\nfunc WriteCustomModelsFile(path string, modelsInput *shared.ModelsInput) 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\tclientModelsInput := modelsInput.ToClientModelsInput()\n\tclientModelsInput.PrepareUpdate()\n\n\tjsonData, err := json.MarshalIndent(clientModelsInput, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshalling models: %v\", err)\n\t}\n\n\terr = os.WriteFile(path, jsonData, 0644)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing file: %v\", err)\n\t}\n\n\terr = SaveCustomModelsHash(path, modelsInput)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error saving hash file: %v\", err)","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/custom_models.go#L120-L156","documentation":"WriteCustomModelsFile creates the parent directory of the target custom-models JSON with os.MkdirAll(..., 0755) before writing; a directory-creation failure is wrapped as 'error creating directory: %v'.","triggerScenarios":"os.MkdirAll(filepath.Dir(path), 0755) fails — parent path component is a file, permission denied, read-only filesystem, or invalid path characters.","commonSituations":"Config directory path exists as a regular file; HOME misconfigured to a non-writable location; disk full or mounted read-only; sandboxed/containerized environments with restricted filesystem writes.","solutions":["Check the wrapped OS error (%v) for the exact mkdir failure","Verify filepath.Dir(path) is writable and no file occupies a directory component of the path","Fix permissions (chmod/chown) or free disk space if that is the cause","Correct HOME/config-path configuration so the directory lands somewhere writable"],"exampleFix":"// before\nerr := os.MkdirAll(filepath.Dir(path), 0755)\nif err != nil {\n    return fmt.Errorf(\"error creating directory: %v\", err)\n}\n// after: caller preflight\nif info, err := os.Stat(filepath.Dir(path)); err == nil && !info.IsDir() {\n    os.Remove(filepath.Dir(path)) // file blocking directory creation\n}","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(path)\nif info, err := os.Stat(dir); err == nil && !info.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory\", dir)\n}\nif err := syscall.Access(dir, syscall.O_RDWR); err != nil {\n    return fmt.Errorf(\"directory not writable: %s\", dir)\n}","typeGuard":"func dirWritable(path string) bool {\n    info, err := os.Stat(path)\n    if err != nil || !info.IsDir() {\n        return false\n    }\n    return info.Mode().Perm()&0200 != 0\n}","tryCatchPattern":"err := WriteCustomModelsFile(path, modelsInput)\nif err != nil && strings.Contains(err.Error(), \"error creating directory\") {\n    fmt.Fprintf(os.Stderr, \"cannot create %s — check permissions/disk: %v\\n\", filepath.Dir(path), err)\n    os.Exit(1)\n}","preventionTips":["Ensure the state directory path is not occupied by a regular file","Verify the parent directory is writable (check HOME/config path config)","Monitor disk space and mount flags (read-only) in CI/container environments"],"tags":["filesystem","permissions","custom-models","cli"],"backgroundTag":"mkdir-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}