{"record":{"id":"469fb6a97ab618b3","repo":"ahmetb/kubectx","slug":"cannot-read-current-namespace-w","errorCode":null,"errorMessage":"cannot read current namespace: %w","messagePattern":"cannot read current namespace: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubens/list.go","lineNumber":60,"sourceCode":"\t}\n\treturn formatNamespaceList(kc, stdout)\n}\n\n// formatNamespaceList writes the sorted, current-namespace-highlighted list\n// 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) {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubens/list.go#L42-L78","documentation":"NamespaceOfContext failed to read the namespace configured for the current context. Fires when the context entry exists but its namespace field cannot be read (malformed context entry), not when the namespace is simply empty.","triggerScenarios":"Thrown at cmd/kubens/list.go:60 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the context entry's namespace field in the kubeconfig","Fix malformed values (namespace must be a string scalar or absent)","Rerun kubens after repair"],"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"}