{"record":{"id":"76e2ac13a58cb224","repo":"ahmetb/kubectx","slug":"contexts-is-not-a-sequence-node","errorCode":null,"errorMessage":"\"contexts\" is not a sequence node","messagePattern":"\"contexts\" is not a sequence node","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/kubeconfig/contexts.go","lineNumber":33,"sourceCode":"package 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}\n\t\tcontext, err := contexts.Pipe(yaml.Lookup(\"[name=\" + name + \"]\"))\n\t\tif err != nil {","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/internal/kubeconfig/contexts.go#L15-L51","documentation":"Type-guard error in contextsNodeOf: the 'contexts' field exists in the kubeconfig YAML but its node kind is not a sequence (list). E.g. 'contexts: foo' (a scalar) or a mapping instead of a list. The kubeconfig is structurally invalid for context operations.","triggerScenarios":"Thrown at internal/kubeconfig/contexts.go:33 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the kubeconfig so 'contexts' is a YAML list of context objects","Compare against a valid kubeconfig or regenerate it with `kubectl config set-context`"],"exampleFix":null,"handlingStrategy":"type-guard","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"}