ahmetb/kubectx · error
kubeconfig error: %w
Error message
kubeconfig error: %w
What it means
Wrapper error in ListOp.Run: kc.Parse() failed with an error other than 'kubeconfig file not found' (which is downgraded to a warning), meaning a real load/decode failure — bad YAML, permissions, or an invalid file among those in KUBECONFIG. Wrapped with %w; the context list aborts.
Source
Thrown at cmd/kubectx/list.go:42
"github.com/ahmetb/kubectx/internal/kubeconfig"
"github.com/ahmetb/kubectx/internal/printer"
)
// ListOp describes listing contexts.
type ListOp struct{}
func (_ ListOp) Run(stdout, stderr io.Writer) 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)
}
return formatContextList(kc, stdout)
}
// formatContextList writes the sorted, current-context-highlighted list of
// contexts from kc to w (one per line). The format mirrors what ListOp.Run
// prints so that the interactive fzf picker shows the same list the user would
// see from `kubectx | fzf`.
func formatContextList(kc *kubeconfig.Kubeconfig, w io.Writer) error {
ctxs, err := kc.ContextNames()
if err != nil {
return fmt.Errorf("failed to get context names: %w", err)
}
natsort.Sort(ctxs)
cur, err := kc.GetCurrentContext()
if err != nil {
return fmt.Errorf("failed to get current context: %w", err)View on GitHub (pinned to 12ad6fb22e)
Solutions
- Read the wrapped cause; typically fix malformed YAML or file permissions
- Test with `kubectl config view` to isolate the bad file in KUBECONFIG
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at cmd/kubectx/list.go:42 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/f8a1a009f9d0acc2.
Report an issue: GitHub.