{"record":{"id":"f910b33b17cb942e","repo":"derailed/k9s","slug":"fail-to-load-rawconfig-w","errorCode":null,"errorMessage":"fail to load rawConfig: %w","messagePattern":"fail to load rawConfig: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":162,"sourceCode":"\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 {\n\t\treturn \"\", fmt.Errorf(\"fail to load rawConfig: %w\", err)\n\t}\n\n\treturn cfg.CurrentContext, nil\n}\n\nfunc (c *Config) CurrentContextNamespace() (string, error) {\n\tname, err := c.CurrentContextName()\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tcontext, err := c.GetContext(name)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn context.Namespace, nil\n}\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/client/config.go#L144-L180","documentation":"Returned by Config.CurrentContextName (internal/client/config.go:162) when c.RawConfig() — the clientcmd load-and-merge of all KUBECONFIG files — fails. The underlying error is wrapped with %w, so the real cause (YAML parse error, unreadable file, invalid merge) is preserved in the chain. Every consumer of CurrentContextName inherits this failure.","triggerScenarios":"Any clientcmd loading-rule failure: malformed YAML in a kubeconfig file (tabs, broken indentation), a file listed in KUBECONFIG that cannot be read (permissions), or content that does not unmarshal into api.Config.","commonSituations":"Hand-edited kubeconfig with a syntax slip; a tool writing partial output concurrently (crashed mid-write); KUBECONFIG=/home/user/.kube/config:/etc/edge-cluster where one entry is corrupt; file permissions changed after a privilege drop.","solutions":["Reproduce outside k9s: kubectl config view — it will print the same parse error and usually the file path","Run a YAML linter (yamllint) on each file in $KUBECONFIG and fix the reported line","If a file is unreadable, fix permissions or remove it from KUBECONFIG","Restore from backup (~/.kube/config.bak) or regenerate the file with kubectl config set-cluster/set-credentials/set-context"],"exampleFix":"# before: KUBECONFIG lists a corrupt file\nKUBECONFIG=/home/me/.kube/config:/tmp/broken.yaml k9s\n\n# after: isolate and repair\nkubectl config view --raw   # errors, pointing at broken.yaml\nyamllint /tmp/broken.yaml   # fix reported line, or drop it\nKUBECONFIG=/home/me/.kube/config k9s","handlingStrategy":"validation","validationCode":"import \"k8s.io/client-go/tools/clientcmd\"\n\nfunc kubeconfigLoads() error {\n\trules := clientcmd.NewDefaultClientConfigLoadingRules()\n\tcfg, err := rules.Load()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"kubeconfig problem: %w\", err)\n\t}\n\t_ = cfg // additionally assert current-context resolves if needed\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"name, err := cfg.CurrentContextName()\nif err != nil {\n\t// unwrap: the chain carries the clientcmd parse error incl. file path\n\tlog.Printf(\"kubeconfig unusable: %v\", err)\n\treturn err\n}","preventionTips":["Smoke-test kubeconfigs after manual edits: kubectl config view > /dev/null","Keep backups before editing kubeconfig YAML by hand (cp config config.bak)","Avoid concurrent writers: run one kubelogin/SSO refresh at a time"],"tags":["kubernetes","kubeconfig","yaml","config","parsing"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}