{"record":{"id":"7f0f266c89343572","repo":"ahmetb/kubectx","slug":"failed-to-get-current-context-w-7f0f26","errorCode":null,"errorMessage":"failed to get current context: %w","messagePattern":"failed to get current context: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/delete.go","lineNumber":63,"sourceCode":"\t\t}\n\n\t\t_ = printer.Success(stderr, `Deleted context %s.`, printer.SuccessColor.Sprint(deletedName))\n\t}\n\treturn nil\n}\n\n// deleteContext deletes a context entry by NAME or current-context\n// indicated by \".\".\nfunc deleteContext(name string) (deleteName string, wasActiveContext bool, err error) {\n\tkc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)\n\tdefer kc.Close()\n\tif err := kc.Parse(); err != nil {\n\t\treturn deleteName, false, fmt.Errorf(\"kubeconfig error: %w\", err)\n\t}\n\n\tcur, err := kc.GetCurrentContext()\n\tif err != nil {\n\t\treturn deleteName, false, fmt.Errorf(\"failed to get current context: %w\", err)\n\t}\n\t// resolve \".\" to a real name\n\tif name == \".\" {\n\t\tif cur == \"\" {\n\t\t\treturn deleteName, false, errors.New(\"can't use '.' as the no active context is set\")\n\t\t}\n\t\twasActiveContext = true\n\t\tname = cur\n\t}\n\n\texists, err := kc.ContextExists(name)\n\tif err != nil {\n\t\treturn name, false, fmt.Errorf(\"failed to check context: %w\", err)\n\t}\n\tif !exists {\n\t\treturn name, false, errors.New(\"context does not exist\")\n\t}\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/delete.go#L45-L81","documentation":"Wrapper error in deleteContext: kc.GetCurrentContext() failed while reading current-context, needed to resolve '.' and to warn when deleting the active context. Cause preserved via %w; deletion aborts.","triggerScenarios":"Thrown at cmd/kubectx/delete.go:63 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped cause (usually malformed kubeconfig structure)","Repair the kubeconfig with kubectl before retrying the delete"],"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"}