{"record":{"id":"ce77e4ff6c480707","repo":"ahmetb/kubectx","slug":"contexts-entry-is-nil-ce77e4","errorCode":null,"errorMessage":"\"contexts\" entry is nil","messagePattern":"\"contexts\" entry is nil","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/kubeconfig/contexts.go","lineNumber":31,"sourceCode":"// limitations under the License.\n\npackage kubeconfig\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"slices\"\n\n\t\"sigs.k8s.io/kustomize/kyaml/yaml\"\n)\n\nfunc contextsNodeOf(fe *fileEntry) (*yaml.RNode, error) {\n\tcontexts, err := fe.config.Pipe(yaml.Get(\"contexts\"))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif contexts == nil {\n\t\treturn nil, errors.New(\"\\\"contexts\\\" entry is nil\")\n\t} else if contexts.YNode().Kind != yaml.SequenceNode {\n\t\treturn nil, errors.New(\"\\\"contexts\\\" is not a sequence node\")\n\t}\n\treturn contexts, nil\n}\n\n// contextNodeWithFileIndex searches for a context by name across all files.\n// Returns the context node and the index of the file that contains it.\n// Files without a valid \"contexts\" sequence are skipped, but if errors occur\n// during lookup they are included in the final error message.\nfunc (k *Kubeconfig) contextNodeWithFileIndex(name string) (*yaml.RNode, int, error) {\n\tvar fileErrors []error\n\tfor i := range k.files {\n\t\tcontexts, err := contextsNodeOf(&k.files[i])\n\t\tif err != nil {\n\t\t\tfileErrors = append(fileErrors, fmt.Errorf(\"file %d: %w\", i, err))\n\t\t\tcontinue\n\t\t}","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/internal/kubeconfig/contexts.go#L13-L49","documentation":"Sentinel error in contextsNodeOf: the kyaml Pipe(yaml.Get(\"contexts\")) returned a nil node, meaning the kubeconfig YAML has no top-level 'contexts' field at all (or it is null). Callers like DeleteContextEntry and contextNodeWithFileIndex cannot proceed without that list.","triggerScenarios":"Thrown at internal/kubeconfig/contexts.go:31 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add a 'contexts' section to the kubeconfig or create one via `kubectl config set-context`","Validate the file with `kubectl config view` to see the parsed structure"],"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"}