{"record":{"id":"65747b4ac80579ec","repo":"derailed/k9s","slug":"unable-to-activate-context-q-w","errorCode":null,"errorMessage":"unable to activate context %q: %w","messagePattern":"unable to activate context %q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/config.go","lineNumber":114,"sourceCode":"\t\t\tsetK8sTimeout(flags, d)\n\t\t} else {\n\t\t\tsetK8sTimeout(flags, client.DefaultCallTimeoutDuration)\n\t\t}\n\t}\n\tif isStringSet(flags.Context) {\n\t\tif _, err := c.K9s.ActivateContext(*flags.Context); err != nil {\n\t\t\treturn fmt.Errorf(\"k8sflags. unable to activate context %q: %w\", *flags.Context, err)\n\t\t}\n\t} else {\n\t\tn, err := cfg.CurrentContextName()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to retrieve kubeconfig current context %q: %w\", n, err)\n\t\t}\n\n\t\tif n != \"\" {\n\t\t\t_, err = c.K9s.ActivateContext(n)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"unable to activate context %q: %w\", n, err)\n\t\t\t}\n\t\t} else {\n\t\t\tslog.Debug(\"No context set, skipping context activation\")\n\t\t}\n\t}\n\tif c.K9s.ActiveContextName() != \"\" {\n\t\tslog.Debug(\"Using active context\", slogs.Context, c.K9s.ActiveContextName())\n\t}\n\n\tvar ns string\n\tswitch {\n\tcase k9sFlags != nil && IsBoolSet(k9sFlags.AllNamespaces):\n\t\tns = client.NamespaceAll\n\t\tc.ResetActiveView()\n\tcase isStringSet(flags.Namespace):\n\t\tns = *flags.Namespace\n\t\tc.ResetActiveView()\n\tdefault:","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/config/config.go#L96-L132","documentation":"Returned from internal/config/config.go:114 in the implicit-context branch: the context name n was successfully resolved from the kubeconfig, but the subsequent c.K9s.ActivateContext(n) failed. As with error 87 this is a wrapper — the wrapped %w error carries the true cause from the activation pipeline (context lookup, per-context config load via dir.Load, proxy connectivity check).","triggerScenarios":"Starting with a resolvable current-context whose k9s per-context config is corrupt (contexts/<cluster>/<ctx>.yaml fails to unmarshal), or whose proxy address fails CheckConnectivity when a live connection object already exists, or whose context vanished from the kubeconfig between resolution and activation (race).","commonSituations":"k9s upgrade leaving old-format per-context yaml; proxy config referencing a dead corporate proxy; kubeconfig rewritten by an SSO tool while k9s boots; leftover k9s state directory from another machine.","solutions":["Inspect the full wrapped error chain to identify which activation stage failed","Check the per-context config: cat ~/.local/share/k9s/clusters/*/<ctx>.yaml and validate its YAML (or delete it to regenerate defaults)","If proxy is configured, verify reachability (curl -x <address> https://<api-server>) and fix or remove the address","Re-run kubectl config use-context <ctx> to normalize kubeconfig state and restart k9s"],"exampleFix":"# before\nk9s  # 'unable to activate context \"prod\": ...'\n\n# after: the chain points at the context yaml\ncat ~/.local/share/k9s/clusters/prod-cluster/prod.yaml\nrm ~/.local/share/k9s/clusters/prod-cluster/prod.yaml  # regenerate defaults\nk9s","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"ct, err := k9s.ActivateContext(n)\nif err != nil {\n\tvar root error = err\n\tfor errors.Unwrap(root) != nil {\n\t\troot = errors.Unwrap(root)\n\t}\n\tswitch {\n\tcase strings.Contains(root.Error(), \"getcontext\"):\n\t\t// context vanished from kubeconfig: re-sync state\n\tcase strings.Contains(root.Error(), \"yaml load failed\"):\n\t\t// repair or delete per-context yaml\n\tcase strings.Contains(root.Error(), \"unable to connect\"):\n\t\t// proxy unreachable: fix proxy.address\n\tdefault:\n\t\treturn root\n\t}\n}","preventionTips":["Pin one k9s version across machines sharing the k9s config directory","Validate per-context yaml files with yamllint after manual edits","Keep proxy addresses in DNS names, not IPs, so corporate proxy changes break fewer configs"],"tags":["kubernetes","k9s","context","activation","proxy","wrapped-error"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}