{"record":{"id":"af6c3d22c7442f64","repo":"cli/cli","slug":"failed-to-list-codespaces-w","errorCode":null,"errorMessage":"failed to list codespaces: %w","messagePattern":"failed to list codespaces: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/codespace/stop.go","lineNumber":58,"sourceCode":"func (a *App) StopCodespace(ctx context.Context, opts *stopOptions) error {\n\tvar (\n\t\tcodespaceName = opts.selector.codespaceName\n\t\trepoName      = opts.selector.repoName\n\t\townerName     = opts.userName\n\t)\n\n\tif codespaceName == \"\" {\n\t\tvar codespaces []*api.Codespace\n\t\terr := a.RunWithProgress(\"Fetching codespaces\", func() (err error) {\n\t\t\tcodespaces, err = a.apiClient.ListCodespaces(ctx, api.ListCodespacesOptions{\n\t\t\t\tRepoName: repoName,\n\t\t\t\tOrgName:  opts.orgName,\n\t\t\t\tUserName: ownerName,\n\t\t\t})\n\t\t\treturn\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to list codespaces: %w\", err)\n\t\t}\n\n\t\tvar runningCodespaces []*api.Codespace\n\t\tfor _, c := range codespaces {\n\t\t\tcs := codespace{c}\n\t\t\tif cs.running() {\n\t\t\t\trunningCodespaces = append(runningCodespaces, c)\n\t\t\t}\n\t\t}\n\t\tif len(runningCodespaces) == 0 {\n\t\t\treturn errors.New(\"no running codespaces\")\n\t\t}\n\n\t\tincludeOwner := opts.orgName != \"\"\n\t\tskipPromptForSingleOption := repoName != \"\"\n\t\tcodespace, err := chooseCodespaceFromList(ctx, runningCodespaces, includeOwner, skipPromptForSingleOption)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to choose codespace: %w\", err)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/cli/cli/blob/0eeec0b92edbe70199f9768522f831d3534f41ad/pkg/cmd/codespace/stop.go#L40-L76","documentation":"Returned by the gh codespace stop command when no specific codespace was given and listing candidate codespaces via a.apiClient.ListCodespaces fails. The list is filtered to running codespaces afterwards, but this error means the API call itself errored before filtering.","triggerScenarios":"codespaceName == \"\" and a.RunWithProgress wrapping a.apiClient.ListCodespaces(ctx, api.ListCodespacesOptions{RepoName, OrgName, UserName}) returns an error: invalid/expired auth, API failure, or network error.","commonSituations":"gh auth token expired or lacks the codespaces scope; using --org or --repo filters the token is not entitled to; GitHub API degradation; proxy blocking api.github.com.","solutions":["Run 'gh auth status' and refresh credentials if needed","Drop --org/--repo filters to test whether entitlement scoping causes the failure","Retry after transient network/API errors","Check the wrapped error body for the API's reason (403, 404, 429)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if _, err := apiClient.ListCodespaces(ctx, api.ListCodespacesOptions{}); err != nil {\n    return fmt.Errorf(\"cannot list codespaces: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := stopRun(opts); err != nil && strings.HasPrefix(err.Error(), \"failed to list codespaces:\") {\n    time.Sleep(5 * time.Second)\n    return stopRun(opts) // transient API failure\n}","preventionTips":["Verify 'gh auth status' and codespaces entitlement before scripted stops","Use -c <name> in automation to bypass listing entirely"],"tags":["go","codespaces","api","auth"],"backgroundTag":null,"analyzedSha":"0eeec0b92edbe70199f9768522f831d3534f41ad","analyzedAt":"2026-08-15T12:31:05.478Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}