{"record":{"id":"a53898903b5ea57f","repo":"ahmetb/kubectx","slug":"failed-to-list-namespaces-from-k8s-api-w","errorCode":null,"errorMessage":"failed to list namespaces from k8s API: %w","messagePattern":"failed to list namespaces from k8s API: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubens/list.go","lineNumber":98,"sourceCode":"\t\treturn []string{\"ns1\", \"ns2\"}, nil\n\t}\n\n\tclientset, err := newKubernetesClientSet(kc)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to initialize k8s REST client: %w\", err)\n\t}\n\n\tvar out []string\n\tvar next string\n\tfor {\n\t\tlist, err := clientset.CoreV1().Namespaces().List(\n\t\t\tcontext.Background(),\n\t\t\tmetav1.ListOptions{\n\t\t\t\tLimit:    500,\n\t\t\t\tContinue: next,\n\t\t\t})\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to list namespaces from k8s API: %w\", err)\n\t\t}\n\t\tnext = list.Continue\n\t\tout = slices.Grow(out, len(list.Items))\n\t\tfor _, it := range list.Items {\n\t\t\tout = append(out, it.Name)\n\t\t}\n\t\tif next == \"\" {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn out, nil\n}\n\nfunc newKubernetesClientSet(kc *kubeconfig.Kubeconfig) (*kubernetes.Clientset, error) {\n\tvar cfg *rest.Config\n\tvar err error\n\n\tif paths := kc.ConfigPaths(); len(paths) > 0 {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubens/list.go#L80-L116","documentation":"A paginated CoreV1().Namespaces().List call against the cluster API failed. Causes: RBAC denying namespace list to the authenticated user, API server errors, or the connection dropping mid-pagination (the code loops with Limit 500 + Continue tokens).","triggerScenarios":"Thrown at cmd/kubens/list.go:98 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify RBAC: kubectl auth can-i list namespaces","Retry in case of transient API server unavailability","Check the wrapped API error for Forbidden/Timeout details"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"12ad6fb22e8c546ee2b54e7de38aa51c906832f7","analyzedAt":"2026-09-02T12:23:10.107Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}