{"record":{"id":"859ed02401b039fb","repo":"ahmetb/kubectx","slug":"can-t-use-as-the-no-active-context-is-set","errorCode":null,"errorMessage":"can't use '.' as the no active context is set","messagePattern":"can't use '\\.' as the no active context is set","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/delete.go","lineNumber":68,"sourceCode":"}\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\n\tif err := kc.DeleteContextEntry(name); err != nil {\n\t\treturn name, false, fmt.Errorf(\"failed to modify yaml doc: %w\", err)\n\t}\n\tif err := kc.Save(); err != nil {\n\t\treturn name, wasActiveContext, fmt.Errorf(\"failed to save modified kubeconfig file: %w\", err)","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/delete.go#L50-L86","documentation":"Validation error in deleteContext: the user passed '.' (meaning 'delete the current context'), but GetCurrentContext() returned an empty string, so there is no active context to resolve '.' against. The sentinel guard fires because '.' is only meaningful when current-context is set in the kubeconfig.","triggerScenarios":"Thrown at cmd/kubectx/delete.go:68 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set a current context with `kubectx <NAME>` before using `kubectx -d .`","Delete the target context by its explicit name instead of '.'"],"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"}