{"record":{"id":"f22ab8e36a31ef82","repo":"plandex-ai/plandex","slug":"error-getting-contexts-v","errorCode":null,"errorMessage":"error getting contexts: %v","messagePattern":"error getting contexts: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/result_helpers.go","lineNumber":116,"sourceCode":"\t\tif err != nil {\n\t\t\terrCh <- fmt.Errorf(\"error getting latest plan build description: %v\", err)\n\t\t\treturn\n\t\t}\n\t\tconvoMessageDescriptions = res\n\t\terrCh <- nil\n\t}()\n\n\tgo func() {\n\t\tdefer func() {\n\t\t\tif r := recover(); r != nil {\n\t\t\t\tlog.Printf(\"panic in GetFullCurrentPlanStateParams: %v\\n%s\", r, debug.Stack())\n\t\t\t\terrCh <- fmt.Errorf(\"panic in GetFullCurrentPlanStateParams: %v\\n%s\", r, debug.Stack())\n\t\t\t\truntime.Goexit() // don't allow outer function to continue and double-send to channel\n\t\t\t}\n\t\t}()\n\t\tres, err := GetPlanContexts(orgId, planId, true, false)\n\t\tif err != nil {\n\t\t\terrCh <- fmt.Errorf(\"error getting contexts: %v\", err)\n\t\t\treturn\n\t\t}\n\n\t\tcontexts = res\n\n\t\terrCh <- nil\n\t}()\n\n\tfor i := 0; i < 3; i++ {\n\t\terr := <-errCh\n\t\tif err != nil {\n\t\t\treturn CurrentPlanStateParams{}, err\n\t\t}\n\t}\n\n\treturn CurrentPlanStateParams{\n\t\tOrgId:                    orgId,\n\t\tPlanId:                   planId,","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/result_helpers.go#L98-L134","documentation":"If GetPlanContexts returns an error inside GetFullCurrentPlanStateParams, it is re-wrapped as 'error getting contexts' and aborts the whole plan-state load (the collector loop returns on the first non-nil error).","triggerScenarios":"GetPlanContexts fails: contexts directory unreadable (non-ENOENT), a context file unreadable or fails JSON unmarshal, or one of its internal goroutines panics/errors.","commonSituations":"Context files truncated by a crash; permissions changed on the contexts dir; invalid JSON from a manual edit or partial write; storage corruption after a disk issue.","solutions":["Examine the wrapped child error for the exact file or directory","Repair permissions or delete/fix the corrupt context file","Restore the plan's contexts directory from backup","Avoid running concurrent deletions against the plans data dir","Consider making single-file corruption non-fatal by skipping bad contexts"],"exampleFix":"// before\nif err != nil {\n\treturn CurrentPlanStateParams{}, err\n}\n// after\nif err != nil {\n\tlog.Printf(\"contexts load failed for %s/%s: %v\", orgId, planId, err)\n\treturn CurrentPlanStateParams{OrgId: orgId, PlanId: planId}, nil\n}","handlingStrategy":"fallback","validationCode":"func contextsReadable(orgId, planId string) error {\n\tdir := getPlanContextsDir(orgId, planId)\n\tfiles, err := os.ReadDir(dir)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil\n\t\t}\n\t\treturn err\n\t}\n\tfor _, f := range files {\n\t\tb, err := os.ReadFile(filepath.Join(dir, f.Name()))\n\t\tif err != nil || !json.Valid(b) {\n\t\t\treturn fmt.Errorf(\"bad context file %s\", f.Name())\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":"func isPermissionErr(err error) bool {\n\tvar pe *os.PathError\n\treturn errors.As(err, &pe) && errors.Is(pe.Err, syscall.EACCES)\n}","tryCatchPattern":"params, err := db.GetFullCurrentPlanStateParams(orgId, planId)\nif err != nil && strings.Contains(err.Error(), \"error getting contexts\") {\n\tlog.Printf(\"contexts unavailable, continuing without them: %v\", err)\n\tparams.Contexts = nil\n}","preventionTips":["Restore contexts dir from backup rather than deleting files ad hoc","Enforce consistent service-user ownership across data dirs","Use atomic writes for all stored JSON to prevent truncation","Quarantine corrupt files and alert instead of letting load fail entirely","Avoid manual edits to stored context JSON"],"tags":["go","json","filesystem","io"],"backgroundTag":"file-read-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"}