{"record":{"id":"89c4d77a9ea65fb1","repo":"ahmetb/kubectx","slug":"kubectl-config-view-failed-w","errorCode":null,"errorMessage":"kubectl config view failed: %w","messagePattern":"kubectl config view failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubectx/shell.go","lineNumber":66,"sourceCode":"\nfunc resolveKubectl() (string, error) {\n\tif v := os.Getenv(\"KUBECTL\"); v != \"\" {\n\t\treturn v, nil\n\t}\n\tpath, err := exec.LookPath(\"kubectl\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"kubectl is required for --shell but was not found in PATH\")\n\t}\n\treturn path, nil\n}\n\nfunc extractMinimalKubeconfig(kubectlPath, contextName string) ([]byte, error) {\n\tcmd := exec.Command(kubectlPath, \"config\", \"view\", \"--minify\", \"--flatten\",\n\t\t\"--context\", contextName)\n\tcmd.Env = os.Environ()\n\tdata, err := cmd.Output()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"kubectl config view failed: %w\", err)\n\t}\n\treturn data, nil\n}\n\nfunc detectShell() string {\n\tif runtime.GOOS == \"windows\" {\n\t\t// cmd.exe always sets the PROMPT env var, so if it is present\n\t\t// we can reliably assume we are running inside cmd.exe.\n\t\tif os.Getenv(\"PROMPT\") != \"\" {\n\t\t\treturn \"cmd.exe\"\n\t\t}\n\t\t// Otherwise assume PowerShell. PSModulePath is always set on\n\t\t// Windows regardless of the shell, so it cannot be used as a\n\t\t// discriminator; however the absence of PROMPT is a strong\n\t\t// enough signal that we are in a PowerShell session.\n\t\tif pwsh, err := exec.LookPath(\"pwsh\"); err == nil {\n\t\t\treturn pwsh\n\t\t}","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubectx/shell.go#L48-L84","documentation":"The subprocess `kubectl config view --minify --flatten --context <name>` exited non-zero when building the minimal per-context kubeconfig for the isolated shell. The wrapped error is an *exec.ExitError; causes include invalid/expired credentials in that context, unreachable API server during token refresh, or a context whose cluster/user references are broken.","triggerScenarios":"Thrown at cmd/kubectx/shell.go:66 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run kubectl config view --minify --flatten --context <name> manually to see the underlying failure","Refresh credentials for the context (re-login, aws eks update-kubeconfig, etc.)","Verify the context's cluster/server and user entries are well-formed in the kubeconfig"],"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"}