{"record":{"id":"75d5e7ebbe481fb5","repo":"ahmetb/kubectx","slug":"failed-to-get-context-names-w-75d5e7","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":"internal/kubeconfig/contexts.go","lineNumber":85,"sourceCode":"\tnode, _, err := k.contextNodeWithFileIndex(name)\n\treturn node, err\n}\n\nfunc (k *Kubeconfig) ContextNames() ([]string, error) {\n\tseen := make(map[string]bool)\n\tvar names []string\n\n\tfor i := range k.files {\n\t\tcontexts, err := k.files[i].config.Pipe(yaml.Get(\"contexts\"))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to get contexts: %w\", err)\n\t\t}\n\t\tif contexts == nil {\n\t\t\tcontinue\n\t\t}\n\t\tfileNames, err := contexts.ElementValues(\"name\")\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to get context names: %w\", err)\n\t\t}\n\t\tfor _, n := range fileNames {\n\t\t\tif !seen[n] {\n\t\t\t\tseen[n] = true\n\t\t\t\tnames = append(names, n)\n\t\t\t}\n\t\t}\n\t}\n\treturn names, nil\n}\n\nfunc (k *Kubeconfig) ContextExists(name string) (bool, error) {\n\tnames, err := k.ContextNames()\n\tif err != nil {\n\t\treturn false, err\n\t}\n\treturn slices.Contains(names, name), nil\n}","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/internal/kubeconfig/contexts.go#L67-L103","documentation":"Inside ContextNames, ElementValues(\"name\") failed to extract the name field values from the contexts sequence of a kubeconfig file. Fires when list elements lack the expected 'name' key structure or are malformed, after the contexts list itself was retrieved.","triggerScenarios":"Thrown at internal/kubeconfig/contexts.go:85 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure every entry under contexts is a mapping with a 'name' key","Remove entries that are scalars or missing 'name'","Rerun kubectx after fixing the file"],"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"}