{"record":{"id":"4fb8c4eea76bc021","repo":"ahmetb/kubectx","slug":"failed-to-get-contexts-w","errorCode":null,"errorMessage":"failed to get contexts: %w","messagePattern":"failed to get contexts: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/kubeconfig/contexts.go","lineNumber":78,"sourceCode":"\t\treturn nil, -1, fmt.Errorf(\"context with name %q not found (errors in files: %w)\",\n\t\t\tname, errors.Join(fileErrors...))\n\t}\n\treturn nil, -1, fmt.Errorf(\"context with name %q not found\", name)\n}\n\nfunc (k *Kubeconfig) contextNode(name string) (*yaml.RNode, error) {\n\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","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/internal/kubeconfig/contexts.go#L60-L96","documentation":"Inside ContextNames, the kyaml Pipe(yaml.Get(\"contexts\")) failed for one of the merged kubeconfig files while enumerating context names. The fault is in the top-level contexts field of that file; a missing field is fine (nil is skipped), so this is a structural read error.","triggerScenarios":"Thrown at internal/kubeconfig/contexts.go:78 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the contexts key in each KUBECONFIG file — it must be a YAML list or absent","Fix or delete the malformed file","Verify with kubectl config get-contexts which file breaks parsing"],"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"}