{"record":{"id":"d8321789363daa82","repo":"ahmetb/kubectx","slug":"could-not-list-namespaces-is-the-cluster-accessib","errorCode":null,"errorMessage":"could not list namespaces (is the cluster accessible?): %w","messagePattern":"could not list namespaces \\(is the cluster accessible\\?\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubens/list.go","lineNumber":65,"sourceCode":"// of namespaces available in the current context to w (one per line). It\n// mirrors what ListOp.Run prints so the interactive fzf picker shows the same\n// list the user would see from `kubens | fzf`.\nfunc formatNamespaceList(kc *kubeconfig.Kubeconfig, w io.Writer) error {\n\tctx, err := kc.GetCurrentContext()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get current context: %w\", err)\n\t}\n\tif ctx == \"\" {\n\t\treturn errors.New(\"current-context is not set\")\n\t}\n\tcurNs, err := kc.NamespaceOfContext(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot read current namespace: %w\", err)\n\t}\n\n\tns, err := queryNamespaces(kc)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not list namespaces (is the cluster accessible?): %w\", err)\n\t}\n\n\tfor _, c := range ns {\n\t\ts := c\n\t\tif c == curNs {\n\t\t\ts = printer.ActiveItemColor.Sprint(c)\n\t\t}\n\t\tfmt.Fprintf(w, \"%s\\n\", s)\n\t}\n\treturn nil\n}\n\nfunc queryNamespaces(kc *kubeconfig.Kubeconfig) ([]string, error) {\n\tif os.Getenv(\"_MOCK_NAMESPACES\") != \"\" {\n\t\treturn []string{\"ns1\", \"ns2\"}, nil\n\t}\n\n\tclientset, err := newKubernetesClientSet(kc)","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubens/list.go#L47-L83","documentation":"queryNamespaces (via the k8s REST client) failed while listing namespaces, most commonly because the cluster referenced by the current context is unreachable or credentials are rejected. The hint in the message reflects that this is a connectivity/API-level failure, not a local config parse error.","triggerScenarios":"Thrown at cmd/kubens/list.go:65 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Test connectivity: kubectl get namespaces — expect the same failure","Verify the API server URL is reachable (VPN, network, DNS)","Refresh expired credentials for the current context","Set _MOCK_NAMESPACES=1 for local testing without a cluster"],"exampleFix":null,"handlingStrategy":"try-catch","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"}