{"record":{"id":"7b4a830f6c20c3f5","repo":"ahmetb/kubectx","slug":"failed-to-check-context-w-7b4a83","errorCode":null,"errorMessage":"failed to check context: %w","messagePattern":"failed to check context: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/shell_session.go","lineNumber":51,"sourceCode":"func (s *shellSession) run(stderr io.Writer) error {\n\tif err := checkIsolatedMode(); err != nil {\n\t\treturn err\n\t}\n\n\tkubectlPath, err := resolveKubectl()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Verify context exists and get current context for exit message.\n\tkc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)\n\tdefer kc.Close()\n\tif err := kc.Parse(); err != nil {\n\t\treturn fmt.Errorf(\"kubeconfig error: %w\", err)\n\t}\n\texists, err := kc.ContextExists(s.target)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to check context: %w\", err)\n\t}\n\tif !exists {\n\t\treturn fmt.Errorf(\"no context exists with the name: %q\", s.target)\n\t}\n\tpreviousCtx, err := kc.GetCurrentContext()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get current context: %w\", err)\n\t}\n\n\t// Extract minimal kubeconfig for the target context.\n\tdata, err := extractMinimalKubeconfig(kubectlPath, s.target)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to extract kubeconfig for context: %w\", err)\n\t}\n\n\t// Optionally transform the kubeconfig (e.g. rewrite for readonly proxy).\n\tvar cleanup func()\n\tif s.transformKubeconfig != nil {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/shell_session.go#L33-L69","documentation":"ContextExists(s.target) errored while verifying the requested shell context exists. The context lookup itself failed (kyaml traversal error over the contexts list), as opposed to a clean not-found result which is handled separately.","triggerScenarios":"Thrown at cmd/kubectx/shell_session.go:51 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the contexts list in each kubeconfig file for malformed YAML","Run kubectl config get-contexts to identify which file kubectl chokes on","Repair or remove the broken kubeconfig file"],"exampleFix":null,"handlingStrategy":"try-catch","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"}