{"record":{"id":"046bf9f083d9f8b3","repo":"plandex-ai/plandex","slug":"error-getting-current-plan-state-v-046bf9","errorCode":null,"errorMessage":"error getting current plan state: %v","messagePattern":"error getting current plan state: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/diff_helpers.go","lineNumber":22,"sourceCode":"\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"os/exec\"\n\t\"path/filepath\"\n\t\"runtime\"\n\t\"runtime/debug\"\n\n\tshared \"plandex-shared\"\n)\n\nfunc GetPlanDiffs(orgId, planId string, plain bool) (string, error) {\n\tplanState, err := GetCurrentPlanState(CurrentPlanStateParams{\n\t\tOrgId:  orgId,\n\t\tPlanId: planId,\n\t})\n\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error getting current plan state: %v\", err)\n\t}\n\n\t// create temp directory\n\ttempDirPath, err := os.MkdirTemp(getOrgDir(orgId), \"tmp-diffs-*\")\n\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error creating temp dir: %v\", err)\n\t}\n\n\tdefer func() {\n\t\tgo os.RemoveAll(tempDirPath)\n\t}()\n\n\t// init a git repo in the temp dir\n\terr = initGitRepo(tempDirPath)\n\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error initializing git repo: %v\", err)","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/diff_helpers.go#L4-L40","documentation":"GetPlanDiffs starts by calling GetCurrentPlanState to assemble the plan's current file state, and wraps any failure as this error. Without the plan state, diffs cannot be computed, so the function aborts before creating its temp directory.","triggerScenarios":"An anonymous caller invokes GetPlanDiffs while GetCurrentPlanState fails: nonexistent planId/orgId, DB query error, or corrupted/missing plan files referenced by the state.","commonSituations":"Requesting diffs for a deleted or not-yet-created plan; cross-org access where the plan belongs to another org; database connectivity issues mid-request.","solutions":["Check the wrapped %v error to see whether it was a DB error or a missing-plan error","Verify orgId and planId refer to an existing plan visible to the caller","Run migrations and confirm plan/file state tables are intact","Add a pre-check (plan exists) before computing diffs for better error messages"],"exampleFix":"// before\nplanState, err := GetCurrentPlanState(CurrentPlanStateParams{OrgId: orgId, PlanId: planId})\nif err != nil { return \"\", fmt.Errorf(\"error getting current plan state: %v\", err) }\n// after\nif exists, err := PlanExists(orgId, planId); err != nil || !exists {\n    return \"\", fmt.Errorf(\"plan %s not found for org %s\", planId, orgId)\n}\nplanState, err := GetCurrentPlanState(CurrentPlanStateParams{OrgId: orgId, PlanId: planId})","handlingStrategy":"validation","validationCode":"if orgId == \"\" || planId == \"\" {\n    return errors.New(\"orgId and planId are required for plan diffs\")\n}\nexists, err := planExists(orgId, planId)\nif err != nil || !exists {\n    return fmt.Errorf(\"plan %s not found for org %s\", planId, orgId)\n}","typeGuard":null,"tryCatchPattern":"diff, err := db.GetPlanDiffs(orgId, planId, files)\nif err != nil && strings.Contains(err.Error(), \"error getting current plan state\") {\n    log.Printf(\"plan state unavailable: %v\", err)\n    return fmt.Errorf(\"cannot diff plan %s: verify it exists and is accessible\", planId)\n}","preventionTips":["Validate orgId/planId and access permissions before computing diffs","Verify plan creation completes before exposing diff endpoints","Monitor DB health; plan-state queries fail during connectivity loss","Keep plan/file state tables covered by migrations"],"tags":["database","plans","diff","data-access"],"backgroundTag":"plan-state-fetch-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"}