{"record":{"id":"331ebb5c8be87de9","repo":"ahmetb/kubectx","slug":"failed-to-get-context-names-w-331ebb","errorCode":null,"errorMessage":"failed to get context names: %w","messagePattern":"failed to get context names: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/list.go","lineNumber":54,"sourceCode":"\tdefer kc.Close()\n\tif err := kc.Parse(); err != nil {\n\t\tif cmdutil.IsNotFoundErr(err) {\n\t\t\tprinter.Warning(stderr, \"kubeconfig file not found\")\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"kubeconfig error: %w\", err)\n\t}\n\treturn formatContextList(kc, stdout)\n}\n\n// formatContextList writes the sorted, current-context-highlighted list of\n// contexts from kc to w (one per line). The format mirrors what ListOp.Run\n// prints so that the interactive fzf picker shows the same list the user would\n// see from `kubectx | fzf`.\nfunc formatContextList(kc *kubeconfig.Kubeconfig, w io.Writer) error {\n\tctxs, err := kc.ContextNames()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get context names: %w\", err)\n\t}\n\tnatsort.Sort(ctxs)\n\n\tcur, err := kc.GetCurrentContext()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get current context: %w\", err)\n\t}\n\tfor _, c := range ctxs {\n\t\ts := c\n\t\tif c == cur {\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","sourceCodeStart":36,"sourceCodeEnd":71,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/list.go#L36-L71","documentation":"Wrapper error in formatContextList: kc.ContextNames() failed while collecting context names from the parsed kubeconfig (structural/kyaml error). Cause preserved via %w; the sorted list cannot be produced.","triggerScenarios":"Thrown at cmd/kubectx/list.go:54 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped cause for kubeconfig structure issues","Repair the 'contexts' section and rerun"],"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"}