ahmetb/kubectx · error
current-context is not set
Error message
current-context is not set
What it means
Guard error in formatNamespaceList (kubens/list.go): GetCurrentContext() returned an empty string — the kubeconfig has no current-context set. The list/highlight logic needs the current context to determine the active namespace, so listing aborts.
Source
Thrown at cmd/kubens/list.go:56
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
defer kc.Close()
if err := kc.Parse(); err != nil {
return fmt.Errorf("kubeconfig error: %w", err)
}
return formatNamespaceList(kc, stdout)
}
// formatNamespaceList writes the sorted, current-namespace-highlighted list
// of namespaces available in the current context to w (one per line). It
// mirrors what ListOp.Run prints so the interactive fzf picker shows the same
// list the user would see from `kubens | fzf`.
func formatNamespaceList(kc *kubeconfig.Kubeconfig, w io.Writer) error {
ctx, err := kc.GetCurrentContext()
if err != nil {
return fmt.Errorf("failed to get current context: %w", err)
}
if ctx == "" {
return errors.New("current-context is not set")
}
curNs, err := kc.NamespaceOfContext(ctx)
if err != nil {
return fmt.Errorf("cannot read current namespace: %w", err)
}
ns, err := queryNamespaces(kc)
if err != nil {
return fmt.Errorf("could not list namespaces (is the cluster accessible?): %w", err)
}
for _, c := range ns {
s := c
if c == curNs {
s = printer.ActiveItemColor.Sprint(c)
}
fmt.Fprintf(w, "%s\n", s)
}View on GitHub (pinned to 12ad6fb22e)
Solutions
- Set a context with `kubectx <NAME>` before listing namespaces
- Create contexts in the kubeconfig if none exist
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at cmd/kubens/list.go:56 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/defb1d6a74dd0808.
Report an issue: GitHub.