{"record":{"id":"defb1d6a74dd0808","repo":"ahmetb/kubectx","slug":"current-context-is-not-set-defb1d","errorCode":null,"errorMessage":"current-context is not set","messagePattern":"current-context is not set","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubens/list.go","lineNumber":56,"sourceCode":"\tkc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)\n\tdefer kc.Close()\n\tif err := kc.Parse(); err != nil {\n\t\treturn fmt.Errorf(\"kubeconfig error: %w\", err)\n\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}","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubens/list.go#L38-L74","documentation":"Guard error in formatNamespaceList (kubens/list.go): GetCurrentContext() returned an empty string — the kubeconfig has no current-context set. The list/highlight logic needs the current context to determine the active namespace, so listing aborts.","triggerScenarios":"Thrown at cmd/kubens/list.go:56 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set a context with `kubectx <NAME>` before listing namespaces","Create contexts in the kubeconfig if none exist"],"exampleFix":null,"handlingStrategy":"validation","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"}