{"record":{"id":"85c2216cbfdf284e","repo":"ahmetb/kubectx","slug":"failed-to-check-context-w-85c221","errorCode":null,"errorMessage":"failed to check context: %w","messagePattern":"failed to check context: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/rename.go","lineNumber":65,"sourceCode":"\t\treturn err\n\t}\n\tkc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)\n\tdefer kc.Close()\n\tif err := kc.Parse(); err != nil {\n\t\treturn fmt.Errorf(\"kubeconfig error: %w\", err)\n\t}\n\n\tcur, err := kc.GetCurrentContext()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get current context: %w\", err)\n\t}\n\tif op.Old == \".\" {\n\t\top.Old = cur\n\t}\n\n\toldExists, err := kc.ContextExists(op.Old)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to check context: %w\", err)\n\t}\n\tif !oldExists {\n\t\treturn fmt.Errorf(\"context \\\"%s\\\" not found, can't rename it\", op.Old)\n\t}\n\n\tnewExists, err := kc.ContextExists(op.New)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to check context: %w\", err)\n\t}\n\tif newExists {\n\t\tprinter.Warning(stderr, \"context \\\"%s\\\" exists, overwriting it.\", op.New)\n\t\tif err := kc.DeleteContextEntry(op.New); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to delete new context to overwrite it: %w\", err)\n\t\t}\n\t}\n\n\tif err := kc.ModifyContextName(op.Old, op.New); err != nil {\n\t\treturn fmt.Errorf(\"failed to change context name: %w\", err)","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/rename.go#L47-L83","documentation":"ContextExists failed while checking whether the old context name exists in the parsed kubeconfig. It fires when the underlying kyaml lookup over the contexts list errors (malformed YAML structure in a kubeconfig file), not when the context is merely missing. The kubeconfig was already parsed successfully; the fault is in the contexts field of one of the files.","triggerScenarios":"Thrown at cmd/kubectx/rename.go:65 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect each KUBECONFIG file (split on ':') and validate its YAML, especially the top-level contexts list","Run kubectl config get-contexts to see if kubectl can read the same files and reveal the broken one","Fix or remove the malformed kubeconfig file and retry the rename"],"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"}