{"record":{"id":"7beb76675d9cf0e5","repo":"ahmetb/kubectx","slug":"kubeconfig-error-w-7beb76","errorCode":null,"errorMessage":"kubeconfig error: %w","messagePattern":"kubeconfig error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubens/fzf.go","lineNumber":44,"sourceCode":"\t\"github.com/ahmetb/kubectx/internal/cmdutil\"\n\t\"github.com/ahmetb/kubectx/internal/env\"\n\t\"github.com/ahmetb/kubectx/internal/kubeconfig\"\n\t\"github.com/ahmetb/kubectx/internal/printer\"\n)\n\ntype InteractiveSwitchOp struct{}\n\n// TODO(ahmetb) This method is heavily repetitive vs kubectx/fzf.go.\nfunc (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {\n\t// parse kubeconfig just to see if it can be loaded\n\tkc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)\n\tdefer kc.Close()\n\tif err := kc.Parse(); err != nil {\n\t\tif cmdutil.IsNotFoundErr(err) {\n\t\t\tprinter.Warning(stderr, \"kubeconfig file not found\")\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"kubeconfig error: %w\", err)\n\t}\n\n\tvar in bytes.Buffer\n\tif err := formatNamespaceList(kc, &in); err != nil {\n\t\treturn err\n\t}\n\tif in.Len() == 0 {\n\t\treturn errors.New(\"no namespaces found\")\n\t}\n\n\tcmd := exec.Command(\"fzf\", \"--ansi\", \"--no-preview\")\n\tvar out bytes.Buffer\n\tcmd.Stdin = &in\n\tcmd.Stderr = stderr\n\tcmd.Stdout = &out\n\n\tcmd.Env = append(os.Environ(),\n\t\tfmt.Sprintf(\"%s=1\", env.EnvForceColor))","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubens/fzf.go#L26-L62","documentation":"In the fzf interactive mode, Run parses the kubeconfig before listing namespaces. Unlike the plain current-namespace command, a \"not found\" error is handled gracefully with a warning; any other parse failure is wrapped as \"kubeconfig error: %w\". It indicates the kubeconfig exists but cannot be parsed.","triggerScenarios":"`kubens` (interactive fzf mode) invoked when the kubeconfig file loads but kc.Parse() fails on malformed YAML or schema-invalid content; only cmdutil.IsNotFoundErr is special-cased.","commonSituations":"Hand-edited ~/.kube/config with YAML mistakes; truncated config from an interrupted credential write; KUBECONFIG pointing at a non-kubeconfig YAML file.","solutions":["Validate the file with `kubectl config view --raw` to reproduce and locate the parse error","Fix YAML syntax (indentation, tabs, duplicate keys)","Restore the kubeconfig from your cluster provider or backup","Check KUBECONFIG for a wrong file and correct it"],"exampleFix":"// before\n# ~/.kube/config\nclusters:\n\t- name: foo   # tab instead of spaces\n// after\nclusters:\n  - name: foo   # valid indentation","handlingStrategy":"validation","validationCode":"kcPath := os.Getenv(\"KUBECONFIG\")\nif kcPath == \"\" {\n    kcPath = filepath.Join(os.Getenv(\"HOME\"), \".kube\", \"config\")\n}\ndata, err := os.ReadFile(kcPath)\nif err != nil {\n    return fmt.Errorf(\"cannot read kubeconfig: %w\", err)\n}\nvar v map[string]interface{}\nif err := yaml.Unmarshal(data, &v); err != nil {\n    return fmt.Errorf(\"kubeconfig YAML invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := op.Run(stdout, stderr); err != nil {\n    if strings.Contains(err.Error(), \"kubeconfig error:\") {\n        // validate with `kubectl config view` and repair the YAML\n    }\n    return err\n}","preventionTips":["Lint kubeconfig YAML after manual edits","Use kubectl config commands instead of hand-editing","Back up the config before credential-refresh tools rewrite it","Distinguish 'not found' (handled with warning) from parse errors"],"tags":["go","kubeconfig","yaml","fzf","kubernetes"],"backgroundTag":"kubeconfig-parse-error","analyzedSha":"12ad6fb22e8c546ee2b54e7de38aa51c906832f7","analyzedAt":"2026-09-02T12:23:10.107Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}