{"record":{"id":"a1b8e4c4b0589981","repo":"ahmetb/kubectx","slug":"failed-to-delete-new-context-to-overwrite-it-w","errorCode":null,"errorMessage":"failed to delete new context to overwrite it: %w","messagePattern":"failed to delete new context to overwrite it: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/rename.go","lineNumber":78,"sourceCode":"\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)\n\t}\n\tif op.Old == cur {\n\t\tif err := kc.ModifyCurrentContext(op.New); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set current-context to new name: %w\", err)\n\t\t}\n\t}\n\tif err := kc.Save(); err != nil {\n\t\treturn fmt.Errorf(\"failed to save modified kubeconfig: %w\", err)\n\t}\n\t_ = printer.Success(stderr, \"Context %s renamed to %s.\",\n\t\tprinter.SuccessColor.Sprint(op.Old),\n\t\tprinter.SuccessColor.Sprint(op.New))\n\treturn nil","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/rename.go#L60-L96","documentation":"While overwriting an existing target context (op.New), DeleteContextEntry failed to remove the existing entry from the kubeconfig before the rename. Fires when the kyaml delete operation on the contexts sequence errors despite the context being reported as present.","triggerScenarios":"Thrown at cmd/kubectx/rename.go:78 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the contexts list in the kubeconfig for duplicate or malformed entries with the target name","Manually remove the target context entry with kubectl config delete-context <NEW> and retry","Validate the kubeconfig YAML and fix structural issues"],"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"}