{"record":{"id":"8acf71e5d010947d","repo":"ahmetb/kubectx","slug":"failed-to-decode-file-d-w","errorCode":null,"errorMessage":"failed to decode file %d: %w","messagePattern":"failed to decode file (.+?): %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/kubeconfig/kubeconfig.go","lineNumber":85,"sourceCode":"\t}\n\treturn firstErr\n}\n\nfunc (k *Kubeconfig) Parse() error {\n\trwcs, err := k.loader.Load()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to load: %w\", err)\n\t}\n\n\tk.files = make([]fileEntry, 0, len(rwcs))\n\tfor i, f := range rwcs {\n\t\tvar v yaml.Node\n\t\tif err := yaml.NewDecoder(f).Decode(&v); err != nil {\n\t\t\t// Close all file handles on failure to avoid leaks.\n\t\t\tfor _, rf := range rwcs {\n\t\t\t\trf.Close()\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"failed to decode file %d: %w\", i, err)\n\t\t}\n\t\trn := yaml.NewRNode(&v)\n\t\tif rn.YNode().Kind != yaml.MappingNode {\n\t\t\tfor _, rf := range rwcs {\n\t\t\t\trf.Close()\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"kubeconfig file %d is not a map document\", i)\n\t\t}\n\t\tvar p string\n\t\tif ph, ok := f.(PathHinter); ok {\n\t\t\tp = ph.Path()\n\t\t}\n\t\tk.files = append(k.files, fileEntry{f: f, path: p, config: rn})\n\t}\n\treturn nil\n}\n\n// ConfigPaths returns the file paths of all loaded kubeconfig files.","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/internal/kubeconfig/kubeconfig.go#L67-L103","documentation":"YAML decoding of the i-th loaded kubeconfig file failed in Parse: the file content is not valid YAML (or is empty beyond a document). All opened handles are closed to avoid leaks before returning; %d identifies the failing file index in KUBECONFIG order.","triggerScenarios":"Thrown at internal/kubeconfig/kubeconfig.go:85 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Map the file index to the N-th path in KUBECONFIG and lint its YAML","Fix tab/syntax errors in that file or remove it from KUBECONFIG","Empty files should be removed or given a minimal valid document"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"12ad6fb22e8c546ee2b54e7de38aa51c906832f7","analyzedAt":"2026-09-02T12:23:10.107Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}