{"record":{"id":"eed0a58f879dc5a8","repo":"ahmetb/kubectx","slug":"error-deleting-context-s-w","errorCode":null,"errorMessage":"error deleting context \"%s\": %w","messagePattern":"error deleting context \"(.+?)\": %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/delete.go","lineNumber":40,"sourceCode":"\t\"github.com/ahmetb/kubectx/internal/kubeconfig\"\n\t\"github.com/ahmetb/kubectx/internal/printer\"\n)\n\n// DeleteOp indicates intention to delete contexts.\ntype DeleteOp struct {\n\tContexts []string // NAME or '.' to indicate current-context.\n}\n\n// deleteContexts deletes context entries one by one.\nfunc (op DeleteOp) Run(_, stderr io.Writer) error {\n\tif err := checkIsolatedMode(); err != nil {\n\t\treturn err\n\t}\n\tfor _, ctx := range op.Contexts {\n\t\t// TODO inefficiency here. we open/write/close the same file many times.\n\t\tdeletedName, wasActiveContext, err := deleteContext(ctx)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error deleting context \\\"%s\\\": %w\", deletedName, err)\n\t\t}\n\t\tif wasActiveContext {\n\t\t\tprinter.Warning(stderr, \"You deleted the current context. Use \\\"%s\\\" to select a new context.\",\n\t\t\t\tselfName())\n\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)","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/delete.go#L22-L58","documentation":"Wrapper error in DeleteOp.Run: deleteContext failed for the given context name. Any of its inner failures (parse, current-context lookup, existence check, YAML modify, save) are surfaced here with the affected name for per-context reporting while the loop continues with other contexts.","triggerScenarios":"Thrown at cmd/kubectx/delete.go:40 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the wrapped cause to see which step failed","Verify the context name exists (`kubectx`) and the kubeconfig is writable","Retry the delete for the remaining contexts"],"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"}