ahmetb/kubectx · error
kubeconfig error: %w
Error message
kubeconfig error: %w
What it means
Generic kubeconfig parse guard at the top of ListOp.Run: loading or decoding the kubeconfig files failed before namespaces could be listed. Wrapped error distinguishes unreadable files (load) from invalid YAML (decode).
Source
Thrown at cmd/kubens/list.go:41
"slices"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"github.com/ahmetb/kubectx/internal/kubeconfig"
"github.com/ahmetb/kubectx/internal/printer"
)
type ListOp struct{}
func (op ListOp) Run(stdout, stderr io.Writer) error {
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 {View on GitHub (pinned to 12ad6fb22e)
Solutions
- Verify KUBECONFIG file paths exist and are readable
- Validate each file's YAML syntax
- Repair or remove the broken file and rerun kubens
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at cmd/kubens/list.go:41 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/d40c4e793e4e152c.
Report an issue: GitHub.