{"record":{"id":"47882f21d2a1f40e","repo":"plandex-ai/plandex","slug":"error-writing-account-credentials-v","errorCode":null,"errorMessage":"error writing account credentials: %v","messagePattern":"error writing account credentials: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/model_credentials.go","lineNumber":583,"sourceCode":"var cachedAccountCredentials *types.AccountCredentials\n\nfunc SetAccountCredentials(creds *types.AccountCredentials) error {\n\tif auth.Current == nil {\n\t\treturn fmt.Errorf(\"no authenticated user\")\n\t}\n\tdir := filepath.Join(fs.HomePlandexDir, auth.Current.UserId, auth.Current.OrgId)\n\terr := os.MkdirAll(dir, 0700)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating account credentials directory: %v\", err)\n\t}\n\tpath := filepath.Join(dir, \"creds.json\")\n\tbytes, err := json.MarshalIndent(creds, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshalling account credentials: %v\", err)\n\t}\n\terr = os.WriteFile(path, bytes, 0600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing account credentials: %v\", err)\n\t}\n\n\tcachedAccountCredentials = creds\n\n\treturn nil\n}\n\nfunc GetAccountCredentials() (*types.AccountCredentials, error) {\n\tif cachedAccountCredentials != nil {\n\t\treturn cachedAccountCredentials, nil\n\t}\n\n\tif auth.Current == nil {\n\t\treturn nil, fmt.Errorf(\"no authenticated user\")\n\t}\n\tpath := filepath.Join(fs.HomePlandexDir, auth.Current.UserId, auth.Current.OrgId, \"creds.json\")\n\n\tbytes, err := os.ReadFile(path)","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/model_credentials.go#L565-L601","documentation":"SetAccountCredentials writes the marshalled creds.json with os.WriteFile using 0600 permissions. This error wraps the write failure — the marshalled credential bytes could not be persisted to disk, so the in-memory cache is not updated and callers can't rely on stored credentials.","triggerScenarios":"os.WriteFile fails on <HomePlandexDir>/<UserId>/<OrgId>/creds.json: permission denied, path is a directory, disk full, read-only filesystem, or quota exceeded.","commonSituations":"creds.json exists but is owned by another user or read-only; an earlier crash left a directory named creds.json; antivirus/EDR blocking writes to credential files; disk quota exceeded.","solutions":["Check permissions on creds.json from the wrapped error path; chmod 0600 or remove the stale file.","If a directory named creds.json exists, remove it.","Verify disk space/quota (df -h) and that the volume is writable.","Re-run the connect/refresh flow after fixing the filesystem issue."],"exampleFix":"// before: blind write\nerr = os.WriteFile(path, bytes, 0600)\n// after: caller-side check\nif info, statErr := os.Stat(path); statErr == nil && info.IsDir() {\n    return fmt.Errorf(\"%s is a directory; remove it to store credentials\", path)\n}","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(path); err == nil {\n    if info.IsDir() {\n        return fmt.Errorf(\"%s is a directory; remove it to store credentials\", path)\n    }\n    if info.Mode().Perm()&0200 == 0 {\n        return fmt.Errorf(\"%s is not writable\", path)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := SetAccountCredentials(creds); err != nil {\n    if strings.Contains(err.Error(), \"writing account credentials\") {\n        return fmt.Errorf(\"cannot write creds.json — check permissions/disk space at the reported path: %w\", err)\n    }\n    return err\n}","preventionTips":["Ensure creds.json is never replaced by a directory (crash-safe writes use temp file + rename).","Keep ownership of ~/.plandex consistent with the running user.","Monitor disk quota/space on the home volume.","Avoid security software that blocks writes to credential files."],"tags":["filesystem","permissions","io"],"backgroundTag":"file-write-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"}