plandex-ai/plandex · error
error loading accounts: %v
Error message
error loading accounts: %v
What it means
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.
Source
Thrown at app/cli/auth/state.go:58
return fmt.Errorf("error storing account: %v", err)
}
Current = auth
err = writeCurrentAuth()
if err != nil {
return fmt.Errorf("error writing auth: %v", err)
}
return nil
}
func storeAccount(toStore *shared.ClientAccount) error {
accounts, err := loadAccounts()
if err != nil {
return fmt.Errorf("error loading accounts: %v", err)
}
found := false
for i, account := range accounts {
if account.UserId == toStore.UserId {
accounts[i] = toStore
found = true
break
}
}
if !found {
accounts = append(accounts, toStore)
}
bytes, err := json.Marshal(accounts)
if err != nil {View on GitHub (pinned to e2d772072e)
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
Example fix
// before error storing account: error loading accounts: error unmarshalling accounts.json: invalid character 'x' // after $ mv ~/.plandex/accounts.json ~/.plandex/accounts.json.bak $ plandex-cli sign-in # recreates a valid store
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check the store loads cleanly before account writes
if b, err := os.ReadFile(fs.HomeAccountsPath); err == nil {
var accounts []*shared.ClientAccount
if err := json.Unmarshal(b, &accounts); err != nil {
return fmt.Errorf("repair accounts.json before storing: %v", err)
}
} Try / catch
if err := setAuth(auth); err != nil {
if strings.Contains(err.Error(), "error loading accounts") {
// nested cause says read vs unmarshal: fix permissions or back up & delete the file
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- error reading accounts.json: %v
- error unmarshalling accounts.json: %v
- error storing account: %v
- error reading JSON file: %v
- error reading JSON file: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/df5c72c36af5c55e.
Report an issue: GitHub.