{"record":{"id":"a80e717535740c55","repo":"ahmetb/kubectx","slug":"failed-to-get-current-context-w-a80e71","errorCode":null,"errorMessage":"failed to get current context: %w","messagePattern":"failed to get current context: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubens/list.go","lineNumber":53,"sourceCode":"type ListOp struct{}\n\nfunc (op ListOp) Run(stdout, stderr io.Writer) error {\n\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)","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubens/list.go#L35-L71","documentation":"GetCurrentContext errored while determining which context's namespaces to list. The kyaml read of current-context failed structurally (e.g. non-scalar field); an unset current-context is handled separately below.","triggerScenarios":"Thrown at cmd/kubens/list.go:53 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect current-context in each kubeconfig file and fix malformed values","Use kubectl config current-context to find the offending file","Repair the YAML and rerun kubens"],"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"}