{"record":{"id":"a6331efa1da301af","repo":"plandex-ai/plandex","slug":"error-unmarshalling-accounts-json-v","errorCode":null,"errorMessage":"error unmarshalling accounts.json: %v","messagePattern":"error unmarshalling accounts\\.json: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/auth/state.go","lineNumber":30,"sourceCode":"var Current *shared.ClientAuth\n\nfunc loadAccounts() ([]*shared.ClientAccount, error) {\n\tbytes, err := os.ReadFile(fs.HomeAccountsPath)\n\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\t// no accounts\n\t\t\treturn []*shared.ClientAccount{}, nil\n\t\t} else {\n\t\t\treturn nil, fmt.Errorf(\"error reading accounts.json: %v\", err)\n\t\t}\n\t}\n\n\tvar accounts []*shared.ClientAccount\n\terr = json.Unmarshal(bytes, &accounts)\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error unmarshalling accounts.json: %v\", err)\n\t}\n\n\treturn accounts, nil\n}\n\nfunc setAuth(auth *shared.ClientAuth) error {\n\terr := storeAccount(&auth.ClientAccount)\n\n\tif err != nil {\n\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)","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/auth/state.go#L12-L48","documentation":"loadAccounts successfully read accounts.json but json.Unmarshal could not parse its contents into []*shared.ClientAccount. This means the local accounts store is malformed — corrupt, truncated, hand-edited, or written by an incompatible CLI version with a schema change.","triggerScenarios":"json.Unmarshal(bytes, &accounts) fails on the contents of fs.HomeAccountsPath: invalid JSON syntax, wrong top-level type (e.g. an object instead of an array), or fields that don't match shared.ClientAccount.","commonSituations":"File truncated by a crash or full disk mid-write; manual editing that broke JSON; downgrading/upgrading the CLI across a schema change; a stray non-JSON file placed at ~/.plandex/accounts.json.","solutions":["Inspect ~/.plandex/accounts.json and fix or remove the invalid JSON","Back it up, then delete it — the CLI recreates it on next sign-in (you'll need to sign in again)","Validate the JSON with a linter (jq . accounts.json) before restoring","Ensure CLI version matches the file's schema; don't hand-edit the store"],"exampleFix":"// before\n$ cat ~/.plandex/accounts.json\n{\"id\": ...}          # object, not array\nerror unmarshalling accounts.json: json: cannot unmarshal object into Go value of type []*shared.ClientAccount\n// after\n$ mv ~/.plandex/accounts.json ~/.plandex/accounts.json.bak\n$ plandex-cli sign-in   # recreates valid accounts.json","handlingStrategy":"validation","validationCode":"// validate accounts.json parses before auth flows touch it\nbytes, err := os.ReadFile(fs.HomeAccountsPath)\nif err == nil {\n    var accounts []*shared.ClientAccount\n    if err := json.Unmarshal(bytes, &accounts); err != nil {\n        return fmt.Errorf(\"accounts.json corrupt, back it up and re-sign-in: %v\", err)\n    }\n}","typeGuard":"func validAccountsJSON(path string) bool {\n    b, err := os.ReadFile(path)\n    if err != nil { return false }\n    var accounts []*shared.ClientAccount\n    return json.Unmarshal(b, &accounts) == nil\n}","tryCatchPattern":"accounts, err := loadAccounts()\nif err != nil {\n    if strings.Contains(err.Error(), \"error unmarshalling accounts.json\") {\n        // back up the corrupt file, delete it, and re-authenticate\n        os.Rename(fs.HomeAccountsPath, fs.HomeAccountsPath+\".bak\")\n    }\n    return err\n}","preventionTips":["Never hand-edit accounts.json","Back up the file before CLI upgrades/downgrades (schema changes)","Run jq . ~/.plandex/accounts.json to validate after a crash","Ensure writes complete (avoid killing the CLI mid-save / full disk)"],"tags":["json","corrupt-file","accounts-json","unmarshal"],"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-12T22:17:10.623Z"}