ahmetb/kubectx · error
"contexts" is not a sequence node
Error message
"contexts" is not a sequence node
What it means
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.
Source
Thrown at internal/kubeconfig/contexts.go:33
package kubeconfig
import (
"errors"
"fmt"
"slices"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
func contextsNodeOf(fe *fileEntry) (*yaml.RNode, error) {
contexts, err := fe.config.Pipe(yaml.Get("contexts"))
if err != nil {
return nil, err
}
if contexts == nil {
return nil, errors.New("\"contexts\" entry is nil")
} else if contexts.YNode().Kind != yaml.SequenceNode {
return nil, errors.New("\"contexts\" is not a sequence node")
}
return contexts, nil
}
// contextNodeWithFileIndex searches for a context by name across all files.
// Returns the context node and the index of the file that contains it.
// Files without a valid "contexts" sequence are skipped, but if errors occur
// during lookup they are included in the final error message.
func (k *Kubeconfig) contextNodeWithFileIndex(name string) (*yaml.RNode, int, error) {
var fileErrors []error
for i := range k.files {
contexts, err := contextsNodeOf(&k.files[i])
if err != nil {
fileErrors = append(fileErrors, fmt.Errorf("file %d: %w", i, err))
continue
}
context, err := contexts.Pipe(yaml.Lookup("[name=" + name + "]"))
if err != nil {View on GitHub (pinned to 12ad6fb22e)
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`
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at internal/kubeconfig/contexts.go:33 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ahmetb/kubectx@12ad6fb22e (2026-09-02).
Data as JSON: /api/errors/76e2ac13a58cb224.
Report an issue: GitHub.