{"record":{"id":"686716f9aab52ab9","repo":"derailed/k9s","slug":"invalid-current-context-specified-q","errorCode":null,"errorMessage":"invalid current context specified: %q","messagePattern":"invalid current context specified: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":143,"sourceCode":"\tflags.Timeout = c.Flags().Timeout\n\tflags.KubeConfig = c.Flags().KubeConfig\n\n\treturn flags, nil\n}\n\n// CurrentClusterName returns the currently active cluster name.\nfunc (c *Config) CurrentClusterName() (string, error) {\n\tif isSet(c.flags.ClusterName) {\n\t\treturn *c.flags.ClusterName, nil\n\t}\n\tcfg, err := c.RawConfig()\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tct, ok := cfg.Contexts[cfg.CurrentContext]\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"invalid current context specified: %q\", cfg.CurrentContext)\n\t}\n\tif isSet(c.flags.Context) {\n\t\tct, ok = cfg.Contexts[*c.flags.Context]\n\t\tif !ok {\n\t\t\treturn \"\", fmt.Errorf(\"current-cluster - invalid context specified: %q\", *c.flags.Context)\n\t\t}\n\t}\n\n\treturn ct.Cluster, nil\n}\n\n// CurrentContextName returns the currently active config context.\nfunc (c *Config) CurrentContextName() (string, error) {\n\tif isSet(c.flags.Context) {\n\t\treturn *c.flags.Context, nil\n\t}\n\tcfg, err := c.RawConfig()\n\tif err != nil {","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/client/config.go#L125-L161","documentation":"Returned by Config.CurrentClusterName (internal/client/config.go:143) when no --cluster flag is set and the kubeconfig's current-context key names a context that does not exist in the contexts map. The kubeconfig is internally inconsistent: current-context points at a context that was never defined or has been removed. Resolution of the cluster name cannot proceed.","triggerScenarios":"cfg.CurrentContext (from the merged raw kubeconfig) is not a key in cfg.Contexts — e.g. someone deleted the active context with kubectl config delete-context without running use-context afterwards, or hand-edited the YAML leaving a dangling current-context.","commonSituations":"Manual kubeconfig editing; scripts that delete contexts; kubeconfig generated by a tool (oidc-login, kubectx rename) that wrote current-context before writing the context entry; truncated files.","solutions":["Run kubectl config get-contexts and check the CURRENT column against the contexts listed","Point current-context at a real context: kubectl config use-context <existing-context>","Or edit the kubeconfig to fix/remove the dangling current-context key","If multiple files are merged via KUBECONFIG, fix the file that actually carries the stale current-context"],"exampleFix":"# before: kubeconfig has\ncurrent-context: deleted-ctx\ncontexts:\n- name: real-ctx\n\n# after\nkubectl config use-context real-ctx\n# current-context: real-ctx","handlingStrategy":"validation","validationCode":"func validateCurrentContext(cfg *client.Config) error {\n\traw, err := cfg.RawConfig()\n\tif err != nil {\n\t\treturn err\n\t}\n\tif _, ok := raw.Contexts[raw.CurrentContext]; raw.CurrentContext != \"\" && !ok {\n\t\treturn fmt.Errorf(\"kubeconfig current-context %q is dangling; run: kubectl config use-context <name>\", raw.CurrentContext)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never delete the active context without immediately running kubectl config use-context <other>","Lint kubeconfigs in CI (kubeconform or a small YAML+references check) before shipping them to users","Prefer kubectl config use-context over hand-editing current-context in the YAML"],"tags":["kubernetes","kubeconfig","context","cluster","config"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}