{"record":{"id":"4dbc14e43f165cf7","repo":"ahmetb/kubectx","slug":"context-s-not-found-can-t-rename-it","errorCode":null,"errorMessage":"context \"%s\" not found, can't rename it","messagePattern":"context \"(.+?)\" not found, can't rename it","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/rename.go","lineNumber":68,"sourceCode":"\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)\n\t}\n\tif op.Old == cur {\n\t\tif err := kc.ModifyCurrentContext(op.New); err != nil {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/rename.go#L50-L86","documentation":"Validation guard: the rename source context name (op.Old, possibly resolved from current-context when '.' was given) does not exist in any kubeconfig file. This is a user-input error, not an I/O failure; the lookup succeeded and returned not-found.","triggerScenarios":"Thrown at cmd/kubectx/rename.go:68 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run kubectx or kubectl config get-contexts to list valid context names","Check for typos, wrong cluster prefix, or stale names in shell history/scripts","If '.' was used, verify current-context is set — the resolved old name may be empty"],"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"}