ahmetb/kubectx · error
failed to get context names: %w
Error message
failed to get context names: %w
What it means
ContextNames() errored while enumerating context names to feed the fzf interactive picker. Fires when the kyaml read of the contexts list fails in one of the kubeconfig files; note the not-found-file case is handled separately above, so this is a structural/read error.
Source
Thrown at cmd/kubectx/shell_session.go:135
// fzfPickContext launches fzf for interactive context selection.
func fzfPickContext(stderr io.Writer) (string, error) {
if err := checkIsolatedMode(); err != nil {
return "", err
}
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
defer kc.Close()
if err := kc.Parse(); err != nil {
if cmdutil.IsNotFoundErr(err) {
printer.Warning(stderr, "kubeconfig file not found")
return "", nil
}
return "", fmt.Errorf("kubeconfig error: %w", err)
}
ctxNames, err := kc.ContextNames()
if err != nil {
return "", fmt.Errorf("failed to get context names: %w", err)
}
if len(ctxNames) == 0 {
return "", errors.New("no contexts found in the kubeconfig file")
}
var in bytes.Buffer
if err := formatContextList(kc, &in); err != nil {
return "", err
}
cmd := exec.Command("fzf", "--ansi", "--no-preview")
var out bytes.Buffer
cmd.Stdin = &in
cmd.Stderr = stderr
cmd.Stdout = &out
cmd.Env = append(os.Environ(),
fmt.Sprintf("%s=1", env.EnvForceColor))View on GitHub (pinned to 12ad6fb22e)
Solutions
- Validate the YAML of each file in KUBECONFIG, especially the contexts list
- Remove or fix the file that fails to parse (kubectl config get-contexts can help find it)
- Retry the fzf picker after repair
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at cmd/kubectx/shell_session.go:135 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/f7ada0d7a89f264b.
Report an issue: GitHub.