{"record":{"id":"f6d08650f2ac9790","repo":"derailed/k9s","slug":"shell-exec-failed-w","errorCode":null,"errorMessage":"shell exec failed: %w","messagePattern":"shell exec failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/view/exec.go","lineNumber":389,"sourceCode":"\tif len(cfg.Command) > 0 {\n\t\targs = append(args, cfg.Command...)\n\t\targs = append(args, cfg.Args...)\n\t} else {\n\t\tif platform == windowsOS {\n\t\t\targs = append(args, \"--\", \"cmd\", \"/c\", winShellCheck)\n\t\t}\n\t\targs = append(args, \"sh\", \"-c\", shellCheck)\n\t}\n\tslog.Debug(\"Running command with args\", slogs.Args, args)\n\n\tc := color.New(color.BgGreen).Add(color.FgBlack).Add(color.Bold)\n\terr = runK(a, &shellOpts{\n\t\tclear:  true,\n\t\tbanner: c.Sprintf(bannerFmt, fqn, co),\n\t\targs:   args},\n\t)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"shell exec failed: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc nukeK9sShell(a *App) error {\n\tct, err := a.Config.K9s.ActiveContext()\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !ct.FeatureGates.NodeShell || a.Config.K9s.ShellPod == nil {\n\t\treturn nil\n\t}\n\n\tns := a.Config.K9s.ShellPod.Namespace\n\tctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)\n\tdefer cancel()\n","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/view/exec.go#L371-L407","documentation":"This wraps a runK() failure for the banner'd shell command k9s builds (kubectl exec ... sh -c <shellCheck> with a green banner naming the pod/container). Every root cause of runK bubbles here: kubectl missing from PATH, kubectl resolving via cwd (ErrDot), or the TUI failing to suspend. The %w preserves that underlying error.","triggerScenarios":"Pressing the shell key on a pod/container when kubectl is not installed or only present as ./kubectl in k9s' working directory, or when the app cannot suspend the TUI to hand over the terminal.","commonSituations":"Shelling into pods from workstations without a proper kubectl install; per-project kubectl binaries; k9s launched from GUI launchers with a stripped PATH so kubectl is invisible to the process.","solutions":["Read the wrapped cause — 'not in your path' → install kubectl; 'must not be in the current working directory' → remove ./kubectl; 'unable to run command' → retry after UI settles","Confirm kubectl version works from the exact directory/environment k9s runs in","Restart k9s after fixing PATH so it re-inherits the environment"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := runK(a, opts)\nif err != nil {\n    switch {\n    case strings.Contains(err.Error(), \"not in your path\"):\n        // install kubectl\n    case strings.Contains(err.Error(), \"current working directory\"):\n        // remove ./kubectl\n    case strings.Contains(err.Error(), \"unable to run command\"):\n        // retry after TUI settles\n    }\n}","preventionTips":["Pre-install and pre-verify kubectl so runK never fails on resolution","Wrap runK callers and classify the wrapped cause instead of showing the generic 'shell exec failed'","Test shelling into a pod right after k9s setup — it exercises the whole exec chain early"],"tags":["kubernetes","k9s","shell","exec","kubectl"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}