{"record":{"id":"0628efd657a2446a","repo":"derailed/k9s","slug":"command-failed-check-k9s-logs-w","errorCode":null,"errorMessage":"command failed. Check k9s logs: %w","messagePattern":"command failed\\. Check k9s logs: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/view/exec.go","lineNumber":605,"sourceCode":"\t\t}\n\t\tcmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr\n\t\t_, _ = cmd.Stdout.Write([]byte(opts.banner))\n\n\t\tslog.Debug(\"Exec started\")\n\t\terr := cmd.Run()\n\t\tvar ex *exec.ExitError\n\t\t// Check if exec failed from a signal\n\t\tif errors.As(err, &ex) && !ex.Exited() {\n\t\t\treturn nil\n\t\t}\n\t\tslog.Debug(\"Command exec done\", slogs.Error, err)\n\t\tif err == nil {\n\t\t\tstatusChan <- fmt.Sprintf(\"Command completed successfully: %q\", cmd.String())\n\t\t}\n\t\tclose(statusChan)\n\n\t\tif err != nil {\n\t\t\terr = fmt.Errorf(\"command failed. Check k9s logs: %w\", err)\n\t\t}\n\n\t\treturn err\n\t}\n\n\tlast := len(cmds) - 1\n\tfor i := range cmds {\n\t\tcmds[i].Stderr = os.Stderr\n\t\tif i+1 < len(cmds) {\n\t\t\tr, w := io.Pipe()\n\t\t\tcmds[i].Stdout, cmds[i+1].Stdin = w, r\n\t\t}\n\t}\n\tcmds[last].Stdout = os.Stdout\n\n\tfor _, cmd := range cmds {\n\t\tslog.Debug(\"Starting command\", slogs.Command, cmd)\n\t\tif err := cmd.Start(); err != nil {","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/view/exec.go#L587-L623","documentation":"After executing a user command, k9s inspects the error: signal-killed ExitErrors (exited=false) are forgiven and nil is returned, but any other non-nil error — normally a normal non-zero exit (exec.ExitError with Exited()=true) — is wrapped as 'command failed. Check k9s logs' because the command's stdout/stderr were streamed into k9s' log rather than the flash.","triggerScenarios":"Running a command through k9s (shell-outs, kubectl prompts, plugin execs) where the command exits non-zero: kubectl hitting a not-found or RBAC error, a grep with no matches (exit 1), a script failing its own checks.","commonSituations":":!kubectl delete pod foo where foo is already gone; commands failing under the active k9s context/impersonation but succeeding in the user's default kubectl context; pipelines whose last command returns non-zero.","solutions":["Open k9s logs (default ~/Library/Logs/k9s or ~/.local/state/k9s logs, or launch k9s in a terminal to see stderr) and find the 'Command exec done' debug line with the captured output","Reproduce manually with the same flags k9s passes: --context, --kubeconfig, --as/--as-group when impersonation is active","Fix the underlying command; the exit code belongs to your command, not k9s"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := runCmd()\nif err != nil {\n    var ex *exec.ExitError\n    if errors.As(err, &ex) {\n        if code := ex.ExitCode(); code != 0 {\n            log.Printf(\"command exited %d — see k9s log for captured output\", code)\n        }\n        return // signal kills (Exited()==false) are already filtered upstream\n    }\n    return err\n}","preventionTips":["Keep k9s log level at debug so command output is captured for diagnosis","Re-run failing commands manually with the same --context/--as flags k9s injects","Expect exit code semantics from your own commands — non-zero exit is a result, not a k9s fault"],"tags":["kubernetes","k9s","exec","command","exit-code"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}