{"record":{"id":"e5b9e46ee9a69e4f","repo":"ahmetb/kubectx","slug":"kubeconfig-file-d-is-not-a-map-document","errorCode":null,"errorMessage":"kubeconfig file %d is not a map document","messagePattern":"kubeconfig file (.+?) is not a map document","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/kubeconfig/kubeconfig.go","lineNumber":92,"sourceCode":"\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.\n// Returns nil if the kubeconfig was not loaded from files (e.g. in tests).\nfunc (k *Kubeconfig) ConfigPaths() []string {\n\tvar paths []string\n\tfor _, fe := range k.files {\n\t\tif fe.path != \"\" {\n\t\t\tpaths = append(paths, fe.path)\n\t\t}","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/internal/kubeconfig/kubeconfig.go#L74-L110","documentation":"Validation guard in Parse: the i-th kubeconfig file decoded to valid YAML but its root node is not a mapping (e.g. the file contains a bare scalar, a list, or only comments). Handles are closed and the file index is reported.","triggerScenarios":"Thrown at internal/kubeconfig/kubeconfig.go:92 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Open the N-th KUBECONFIG file and ensure the document is a YAML mapping with apiVersion/kind/contexts style keys","Remove files that contain stray non-document content","Restore from backup or regenerate the file"],"exampleFix":null,"handlingStrategy":"validation","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"}