{"record":{"id":"868bb923d3ca635a","repo":"kubernetes/kops","slug":"error-loading-kubeconfig-v","errorCode":null,"errorMessage":"error loading kubeconfig: %v","messagePattern":"error loading kubeconfig: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/kubeconfig/kubecfg_builder.go","lineNumber":56,"sourceCode":"\tKubeUser     string\n\tKubePassword string\n\n\tCACerts    []byte\n\tClientCert []byte\n\tClientKey  []byte\n\n\tAuthenticationExec []string\n}\n\n// Create new KubeconfigBuilder\nfunc NewKubeconfigBuilder() *KubeconfigBuilder {\n\treturn &KubeconfigBuilder{}\n}\n\nfunc (b *KubeconfigBuilder) DeleteKubeConfig(configAccess clientcmd.ConfigAccess) error {\n\tconfig, err := configAccess.GetStartingConfig()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error loading kubeconfig: %v\", err)\n\t}\n\n\tif config == nil || clientcmdapi.IsConfigEmpty(config) {\n\t\tklog.V(2).Info(\"kubeconfig is empty\")\n\t\treturn nil\n\t}\n\n\tdelete(config.Clusters, b.Context)\n\tdelete(config.AuthInfos, b.Context)\n\tdelete(config.AuthInfos, fmt.Sprintf(\"%s-basic-auth\", b.Context))\n\tdelete(config.Contexts, b.Context)\n\n\tif config.CurrentContext == b.Context {\n\t\tconfig.CurrentContext = \"\"\n\t}\n\n\tif err := clientcmd.ModifyConfig(configAccess, *config, false); err != nil {\n\t\treturn fmt.Errorf(\"error writing kubeconfig: %v\", err)","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/kubeconfig/kubecfg_builder.go#L38-L74","documentation":"clientcmd failed to load the existing kubeconfig while preparing to delete the context: the file is present but cannot be parsed (malformed YAML) or read, so the deletion cannot proceed safely.","triggerScenarios":"Thrown at pkg/kubeconfig/kubecfg_builder.go:56 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Validate the kubeconfig with kubectl config view to locate the syntax error","Fix or remove the broken kubeconfig file","Check file permissions"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}