{"record":{"id":"4dc718428396ee0f","repo":"derailed/k9s","slug":"no-active-context-available","errorCode":null,"errorMessage":"no active context available","messagePattern":"no active context available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/k9s.go","lineNumber":220,"sourceCode":"\t\treturn \"\", err\n\t}\n\n\treturn act.Namespace.Active, nil\n}\n\n// ActiveContextName returns the active context name.\nfunc (k *K9s) ActiveContextName() string {\n\treturn k.getActiveContextName()\n}\n\n// ActiveContext returns the currently active context.\nfunc (k *K9s) ActiveContext() (*data.Context, error) {\n\tif cfg := k.getActiveConfig(); cfg != nil && cfg.Context != nil {\n\t\treturn cfg.Context, nil\n\t}\n\tctxName := k.ActiveContextName()\n\tif ctxName == \"\" {\n\t\treturn nil, errors.New(\"no active context available\")\n\t}\n\tct, err := k.ActivateContext(ctxName)\n\n\treturn ct, err\n}\n\nfunc (k *K9s) setActiveConfig(c *data.Config) {\n\tk.mx.Lock()\n\tdefer k.mx.Unlock()\n\n\tk.activeConfig = c\n}\n\nfunc (k *K9s) getActiveConfig() *data.Config {\n\tk.mx.RLock()\n\tdefer k.mx.RUnlock()\n\n\treturn k.activeConfig","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/config/k9s.go#L202-L238","documentation":"Returned by K9s.ActiveContext (internal/config/k9s.go:220) when there is no cached active *data.Config and ActiveContextName() returns an empty string. The active context name comes from the k9s config's currentContext, falling back to the kubeconfig's current-context; empty means neither source names a context, so k9s cannot determine which cluster configuration to load.","triggerScenarios":"First run with no kubeconfig or a kubeconfig whose current-context is unset and no K9s context configured; environment where KUBECONFIG points to an empty/invalid file; config state cleared mid-session.","commonSituations":"Fresh machine or CI container without kubectl setup; KUBECONFIG env var pointing to a wrong path; kubeconfig hand-edited and current-context line removed; automated environments that never selected a context.","solutions":["Set a current context in kubeconfig: kubectl config use-context <name>, then restart","Ensure KUBECONFIG points to an existing file with defined contexts (kubectl config get-contexts)","Pass the context explicitly on startup (k9s --context <name>) or set it in the k9s config so ActiveContextName() is never empty","If multiple kubeconfig files are merged, verify the merged result still yields a current-context"],"exampleFix":"# before\n$ KUBECONFIG=/dev/null k9s\n# -> no active context available\n\n# after\n$ kubectl config use-context minikube\n$ k9s --context minikube","handlingStrategy":"validation","validationCode":"if k9sCfg.ActiveContextName() == \"\" {\n    return fmt.Errorf(\"select a context first (k9s --context <name>)\")\n}\nct, err := k9sCfg.ActiveContext()","typeGuard":null,"tryCatchPattern":"ct, err := k9sCfg.ActiveContext()\nif err != nil && strings.Contains(err.Error(), \"no active context\") {\n    // prompt user to pick a context or exit with guidance\n}","preventionTips":["Set current-context in kubeconfig as part of environment provisioning","Always launch k9s with an explicit --context in scripts/CI","Validate kubeconfig presence (KUBECONFIG path) before starting the app"],"tags":["kubernetes","kubeconfig","context","config","startup"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}