{"record":{"id":"2c24b1d034247013","repo":"plandex-ai/plandex","slug":"error-marshalling-current-plan-v","errorCode":null,"errorMessage":"error marshalling current plan: %v","messagePattern":"error marshalling current plan: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/plans.go","lineNumber":47,"sourceCode":"\t\t\treturn fmt.Errorf(\"error unmarshalling current-plans-v2.json: %v\", err)\n\t\t}\n\t} else if !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"error checking if current-plans-v2.json exists: %v\", err)\n\t}\n\n\tif currentPlanSettingsByAccount == nil {\n\t\tcurrentPlanSettingsByAccount = &types.CurrentPlanSettingsByAccount{}\n\t}\n\n\tsettings := types.CurrentPlanSettings{\n\t\tId: id,\n\t}\n\n\t(*currentPlanSettingsByAccount)[auth.Current.UserId] = &settings\n\n\tbytes, err = json.Marshal(currentPlanSettingsByAccount)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshalling current plan: %v\", err)\n\t}\n\n\terr = os.WriteFile(HomeCurrentPlanPath, bytes, 0644)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error writing current plan: %v\", err)\n\t}\n\n\tCurrentPlanId = id\n\n\treturn nil\n}\n\nfunc ClearCurrentPlan() error {\n\tif fs.HomePlandexDir == \"\" {\n\t\treturn fmt.Errorf(\"HomePlandexDir not set\")\n\t}\n\n\tif CurrentProjectId == \"\" || HomeCurrentPlanPath == \"\" {","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/plans.go#L29-L65","documentation":"After updating the in-memory map with the new current plan id for auth.Current.UserId, WriteCurrentPlan serializes it with json.Marshal. Failure here means the CurrentPlanSettingsByAccount value could not be encoded (e.g. a map key that is not a string or an unsupported value type), so nothing is written to disk.","triggerScenarios":"json.Marshal(currentPlanSettingsByAccount) returns an error just before the os.WriteFile call — practically only when the map or CurrentPlanSettings struct contains values json cannot encode (invalid UTF-8 keys, unsupported types). Raised from 'plandex cd' / 'plandex new'.","commonSituations":"A hand-patched or version-mismatched types package with an unsupported field type; corrupted account-id map keys from a modified state file; custom build where CurrentPlanSettings gained a non-encodable field.","solutions":["Verify the types.CurrentPlanSettingsByAccount / CurrentPlanSettings structs only contain JSON-encodable types in your build.","Rebuild the CLI from the matching tag so types match the released schema (go install ./... or the release binary).","Move the corrupt state aside (mv ~/.plandex/current-plans-v2.json{,.bak}) and retry so the map starts empty.","If you modified the types package, add MarshalJSON or change the offending field to an encodable type."],"exampleFix":"// before: unsupported field type in types\nsettings := types.CurrentPlanSettings{Id: id, Callback: func(){}}\n// error marshalling current plan: json: unsupported type: func()\n\n// after: store only encodable data\nsettings := types.CurrentPlanSettings{Id: id}","handlingStrategy":"try-catch","validationCode":"// ensure the state you feed the lib is encodable before calling\nif b, err := json.Marshal(existingState); err != nil {\n\treturn fmt.Errorf(\"state not encodable, refusing to update plan: %v\", err)\n} else { _ = b }","typeGuard":"func jsonEncodable(v any) bool { _, err := json.Marshal(v); return err == nil }","tryCatchPattern":"if err := lib.WriteCurrentPlan(id); err != nil {\n\tif strings.Contains(err.Error(), \"error marshalling current plan\") {\n\t\t// fall back: rebuild state from scratch\n\t\tos.Remove(homePlansPath)\n\t\terr = lib.WriteCurrentPlan(id)\n\t}\n}","preventionTips":["Only build the CLI from official sources so types match the released schema.","Keep all fields in custom CurrentPlanSettings types JSON-encodable.","Round-trip test (Marshal then Unmarshal) any changes to the types package.","Reset the state file if marshal errors persist after a rebuild."],"tags":["cli","json","marshal","serialization"],"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"}