{"record":{"id":"df5c72c36af5c55e","repo":"plandex-ai/plandex","slug":"error-loading-accounts-v-df5c72","errorCode":null,"errorMessage":"error loading accounts: %v","messagePattern":"error loading accounts: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/auth/state.go","lineNumber":58,"sourceCode":"\t\treturn fmt.Errorf(\"error storing account: %v\", err)\n\t}\n\n\tCurrent = auth\n\n\terr = writeCurrentAuth()\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing auth: %v\", err)\n\t}\n\n\treturn nil\n}\n\nfunc storeAccount(toStore *shared.ClientAccount) error {\n\taccounts, err := loadAccounts()\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error loading accounts: %v\", err)\n\t}\n\n\tfound := false\n\tfor i, account := range accounts {\n\t\tif account.UserId == toStore.UserId {\n\t\t\taccounts[i] = toStore\n\t\t\tfound = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif !found {\n\t\taccounts = append(accounts, toStore)\n\t}\n\n\tbytes, err := json.Marshal(accounts)\n\n\tif err != nil {","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/auth/state.go#L40-L76","documentation":"storeAccount begins by loading existing accounts via loadAccounts and wraps any load failure in this error. This nests the underlying cause — either \"error reading accounts.json\" (unreadable file) or \"error unmarshalling accounts.json\" (corrupt JSON) — so the full chain appears in the message.","triggerScenarios":"setAuth → storeAccount → loadAccounts; os.ReadFile on fs.HomeAccountsPath fails with a non-NotExist error, or the file's JSON fails to unmarshal into []*shared.ClientAccount.","commonSituations":"Corrupt or hand-edited accounts.json; permission problems on ~/.plandex (e.g. root-owned after sudo); truncated file from a previous crashed write; schema mismatch after a CLI version change.","solutions":["Read the nested cause: fix file permissions for read errors, or repair/delete the file for unmarshal errors","Back up and remove ~/.plandex/accounts.json so it is recreated on next sign-in","Validate the JSON (jq . accounts.json) if you want to preserve existing accounts","Avoid running the CLI as root/sudo to prevent ownership mismatches"],"exampleFix":"// before\nerror storing account: error loading accounts: error unmarshalling accounts.json: invalid character 'x'\n// after\n$ mv ~/.plandex/accounts.json ~/.plandex/accounts.json.bak\n$ plandex-cli sign-in   # recreates a valid store","handlingStrategy":"try-catch","validationCode":"// pre-check the store loads cleanly before account writes\nif b, err := os.ReadFile(fs.HomeAccountsPath); err == nil {\n    var accounts []*shared.ClientAccount\n    if err := json.Unmarshal(b, &accounts); err != nil {\n        return fmt.Errorf(\"repair accounts.json before storing: %v\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := setAuth(auth); err != nil {\n    if strings.Contains(err.Error(), \"error loading accounts\") {\n        // nested cause says read vs unmarshal: fix permissions or back up & delete the file\n    }\n    return err\n}","preventionTips":["Keep accounts.json valid JSON — don't hand-edit it","Fix ~/.plandex ownership/permissions proactively (no sudo)","Validate with jq after crashes or upgrades","Back up the store before deleting so accounts can be recovered"],"tags":["filesystem","json","accounts-json","nested-error"],"backgroundTag":"json-unmarshal-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"}