{"record":{"id":"3c57afddc4d6ef2a","repo":"plandex-ai/plandex","slug":"error-marshalling-account-credentials-v","errorCode":null,"errorMessage":"error marshalling account credentials: %v","messagePattern":"error marshalling account credentials: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/model_credentials.go","lineNumber":579,"sourceCode":"\t}\n\treturn \"❌\"\n}\n\nvar 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\")","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/model_credentials.go#L561-L597","documentation":"After creating the credentials directory, SetAccountCredentials serializes the AccountCredentials struct with json.MarshalIndent. This error wraps marshal failure; credentials cannot be persisted because the struct cannot be converted to JSON (e.g. an unsupported field type such as a channel, func, or cyclic value).","triggerScenarios":"json.MarshalIndent on *types.AccountCredentials fails — typically only when the struct carries fields not serializable by encoding/json (chan, func, complex) or a custom MarshalJSON returns an error.","commonSituations":"Rare in practice; usually follows a type change in types.AccountCredentials that introduced a non-JSON-serializable field, or a vendored/shared-type version mismatch after an upgrade.","solutions":["Inspect the wrapped error to find the offending field reported by encoding/json.","Ensure types.AccountCredentials contains only JSON-serializable types; add omitempty or json tags for problematic fields.","Rebuild the CLI against the matching version of the shared types package to rule out version skew."],"exampleFix":"// before\ntype AccountCredentials struct { TokenCh chan string }\n// after\ntype AccountCredentials struct { AccessToken string `json:\"accessToken\"` RefreshToken string `json:\"refreshToken\"` ExpiresAt time.Time `json:\"expiresAt\"` }","handlingStrategy":"try-catch","validationCode":"if _, err := json.Marshal(creds); err != nil {\n    return fmt.Errorf(\"AccountCredentials not serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := SetAccountCredentials(creds); err != nil {\n    if strings.Contains(err.Error(), \"marshalling account credentials\") {\n        return fmt.Errorf(\"credential struct contains a non-JSON field — upgrade/align the shared types package: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep types.AccountCredentials composed of JSON-serializable primitives and tagged fields.","Keep the CLI and shared types package versions in sync.","Add a unit test that marshals AccountCredentials to catch schema regressions."],"tags":["json","serialization","types"],"backgroundTag":"json-marshal-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"}