{"record":{"id":"4e47882d1e4b4a62","repo":"plandex-ai/plandex","slug":"error-listing-contexts-v","errorCode":null,"errorMessage":"error listing contexts: %v","messagePattern":"error listing contexts: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/cmd/context_show.go","lineNumber":32,"sourceCode":"func init() {\n\tRootCmd.AddCommand(contextShowCmd)\n}\n\nvar contextShowCmd = &cobra.Command{\n\tUse:   \"show [name-or-index]\",\n\tShort: \"Show the body of a context by name or list index\",\n\tArgs:  cobra.ExactArgs(1),\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tauth.MustResolveAuthWithOrg()\n\t\tlib.MustResolveProject()\n\n\t\tnameOrIndex := args[0]\n\n\t\t// Get list of contexts first\n\t\tcontexts, err := api.Client.ListContext(lib.CurrentPlanId, lib.CurrentBranch)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error listing contexts: %v\\n\", err)\n\t\t\treturn fmt.Errorf(\"error listing contexts: %v\", err)\n\t\t}\n\n\t\tvar contextId string\n\n\t\t// Try parsing as index first\n\t\tif idx, err := strconv.Atoi(nameOrIndex); err == nil {\n\t\t\t// Convert to 0-based index\n\t\t\tidx--\n\t\t\tif idx < 0 || idx >= len(contexts) {\n\t\t\t\treturn fmt.Errorf(\"invalid context index: %s\", nameOrIndex)\n\t\t\t}\n\t\t\tcontextId = contexts[idx].Id\n\t\t} else {\n\t\t\t// Try finding by name\n\t\t\tfound := false\n\t\t\tfor _, ctx := range contexts {\n\t\t\t\tif ctx.Name == nameOrIndex || ctx.FilePath == nameOrIndex {\n\t\t\t\t\tcontextId = ctx.Id","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/cmd/context_show.go#L14-L50","documentation":"The `plandex contexts show` command fetches the plan's context list via api.Client.ListContext(planId, branch) before resolving the given name or index. If that API call fails, the CLI logs the underlying cause and returns this wrapped error, so the command aborts before it can resolve a context. It almost always reflects a network, auth, or server-side problem rather than a bad argument.","triggerScenarios":"Running `plandex contexts show <name-or-index>` when the ListContext HTTP call to the Plandex server fails: server unreachable, expired/invalid session, plan or branch not found server-side, or a 5xx from the daemon.","commonSituations":"The Plandex server/daemon is down or the CLI is pointed at the wrong host; the auth session expired between commands; the current plan was deleted on the server or the branch no longer exists; a proxy/firewall blocks the API connection.","solutions":["Check the log line 'Error listing contexts' printed just above this error for the underlying cause and address it directly.","Verify the Plandex server is reachable (plandex ping / correct PLANDEX_HOST) and that you are logged in with a valid session (re-run `plandex auth` if needed).","Confirm you are inside the correct project directory with an active plan and branch (plandex plans / plandex branches).","Retry after network/proxy issues are resolved; if the server returns 5xx, check server logs."],"exampleFix":"// before\ncmd.RunE = func(cmd *cobra.Command, args []string) error {\n  contexts, err := api.Client.ListContext(lib.CurrentPlanId, lib.CurrentBranch)\n  if err != nil {\n    return fmt.Errorf(\"error listing contexts: %v\", err)\n  }\n  _ = contexts\n  return nil\n}\n// after\ncmd.RunE = func(cmd *cobra.Command, args []string) error {\n  contexts, err := api.Client.ListContext(lib.CurrentPlanId, lib.CurrentBranch)\n  if err != nil {\n    if apiErr, ok := err.(*shared.ApiError); ok {\n      return fmt.Errorf(\"list contexts failed (HTTP %d): %s\", apiErr.Status, apiErr.Msg)\n    }\n    return fmt.Errorf(\"list contexts failed: %w\", err)\n  }\n  _ = contexts\n  return nil\n}","handlingStrategy":"try-catch","validationCode":"// before invoking the command, check server reachability and auth\n// in shell:\n// plandex ping && test -f .plandex/plan.json && echo \"plan context available\"\n// in Go callers of ListContext:\nif lib.CurrentPlanId == \"\" || lib.CurrentBranch == \"\" {\n    return fmt.Errorf(\"no active plan/branch; run inside a plandex project\")\n}","typeGuard":"func isApiErr(err error) (*shared.ApiError, bool) {\n    apiErr, ok := err.(*shared.ApiError)\n    return apiErr, ok\n}","tryCatchPattern":"contexts, err := api.Client.ListContext(planId, branch)\nif err != nil {\n    var apiErr *shared.ApiError\n    if errors.As(err, &apiErr) {\n        // handle by status: 401 -> re-auth, 5xx -> retry later\n    }\n    return fmt.Errorf(\"list contexts failed: %w\", err)\n}","preventionTips":["Run `plandex ping` or a cheap authenticated call before scripted context operations","Re-authenticate when sessions are long-lived; handle 401 by re-running `plandex auth`","Always run the CLI from the project directory with an active plan/branch","Check server/daemon health before batch scripts that hit the API repeatedly"],"tags":["cli","network","api","go"],"backgroundTag":"api-request-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"}