{"record":{"id":"1df417b045a83c43","repo":"plandex-ai/plandex","slug":"failed-to-get-contexts-v","errorCode":null,"errorMessage":"failed to get contexts: %v","messagePattern":"failed to get contexts: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/context_auto_load.go","lineNumber":20,"sourceCode":"\nimport (\n\t\"context\"\n\t\"encoding/base64\"\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"plandex-cli/api\"\n\t\"plandex-cli/types\"\n\tshared \"plandex-shared\"\n\t\"sync\"\n\n\t\"github.com/sashabaranov/go-openai\"\n)\n\nfunc AutoLoadContextFiles(ctx context.Context, files []string) (string, error) {\n\tcontexts, err := api.Client.ListContext(CurrentPlanId, CurrentBranch)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get contexts: %v\", err)\n\t}\n\n\tvar totalSize int64\n\ttotalContexts := len(contexts)\n\n\tfor _, context := range contexts {\n\t\ttotalSize += context.BodySize\n\t}\n\n\tloadContextReqsByIndex := make(map[int]*shared.LoadContextParams)\n\tfilesSkippedTooLarge := []filePathWithSize{}\n\tfilesSkippedAfterSizeLimit := []string{}\n\n\tvar mu sync.Mutex\n\terrCh := make(chan error, len(files))\n\n\tfor i, path := range files {\n\t\ttotalContexts++","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/context_auto_load.go#L2-L38","documentation":"AutoLoadContextFiles wraps a failure from api.Client.ListContext(CurrentPlanId, CurrentBranch), the remote call that enumerates contexts for the current plan/branch. Nothing was loaded, so the function returns an empty string and this error, usually indicating connectivity or an invalid plan/branch identifier.","triggerScenarios":"api.Client.ListContext(CurrentPlanId, CurrentBranch) returns an error: API unreachable/unauthenticated, CurrentPlanId or CurrentBranch empty or pointing at a deleted plan/branch, or server 4xx/5xx.","commonSituations":"Running before any plan/branch was initialized (CurrentPlanId is zero-value), expired API credentials, network outage, or the plan/branch being deleted remotely while a stale local reference remains.","solutions":["Verify the client is authenticated and the API base URL is reachable (check credentials/env).","Ensure CurrentPlanId and CurrentBranch are set — initialize or select a plan/branch before calling AutoLoadContextFiles.","Refresh the local plan/branch reference if it was deleted remotely.","Retry on transient network errors; return a graceful empty result if no contexts are configured.","Check server status / API version compatibility if 5xx persists."],"exampleFix":"// before\nfunc AutoLoadContextFiles(ctx context.Context, files []string) (string, error) {\n    contexts, err := api.Client.ListContext(CurrentPlanId, CurrentBranch)\n// after\nfunc AutoLoadContextFiles(ctx context.Context, files []string) (string, error) {\n    if CurrentPlanId == \"\" || CurrentBranch == \"\" {\n        return \"\", nil // nothing to load yet\n    }\n    contexts, err := api.Client.ListContext(CurrentPlanId, CurrentBranch)","handlingStrategy":"try-catch","validationCode":"if CurrentPlanId == \"\" || CurrentBranch == \"\" {\n    return \"\", nil // no plan/branch selected yet; nothing to load\n}\nif err := api.Client.Ping(ctx); err != nil {\n    return \"\", fmt.Errorf(\"API unreachable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"contexts, err := api.Client.ListContext(CurrentPlanId, CurrentBranch)\nif err != nil {\n    var apiErr *api.Error\n    if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusUnauthorized {\n        return \"\", fmt.Errorf(\"re-authenticate: %w\", err)\n    }\n    return \"\", fmt.Errorf(\"failed to get contexts: %v\", err)\n}","preventionTips":["Initialize/select a plan and branch before calling AutoLoadContextFiles.","Check API authentication and reachability at startup.","Handle deleted remote plans/branches by resyncing local references.","Add retry with backoff for transient API errors."],"tags":["api","network","context-loading","authentication"],"backgroundTag":"api-list-request-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"}