derailed/k9s · error

command failed. Check k9s logs: %w

Error message

command failed. Check k9s logs: %w

What it means

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.

Source

Thrown at internal/view/exec.go:605

		}
		cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
		_, _ = cmd.Stdout.Write([]byte(opts.banner))

		slog.Debug("Exec started")
		err := cmd.Run()
		var ex *exec.ExitError
		// Check if exec failed from a signal
		if errors.As(err, &ex) && !ex.Exited() {
			return nil
		}
		slog.Debug("Command exec done", slogs.Error, err)
		if err == nil {
			statusChan <- fmt.Sprintf("Command completed successfully: %q", cmd.String())
		}
		close(statusChan)

		if err != nil {
			err = fmt.Errorf("command failed. Check k9s logs: %w", err)
		}

		return err
	}

	last := len(cmds) - 1
	for i := range cmds {
		cmds[i].Stderr = os.Stderr
		if i+1 < len(cmds) {
			r, w := io.Pipe()
			cmds[i].Stdout, cmds[i+1].Stdin = w, r
		}
	}
	cmds[last].Stdout = os.Stdout

	for _, cmd := range cmds {
		slog.Debug("Starting command", slogs.Command, cmd)
		if err := cmd.Start(); err != nil {

View on GitHub (pinned to 2d3ccc6ba2)

Solutions

  1. 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
  2. Reproduce manually with the same flags k9s passes: --context, --kubeconfig, --as/--as-group when impersonation is active
  3. Fix the underlying command; the exit code belongs to your command, not k9s
Defensive patterns

Strategy: try-catch

Try / catch

err := runCmd()
if err != nil {
    var ex *exec.ExitError
    if errors.As(err, &ex) {
        if code := ex.ExitCode(); code != 0 {
            log.Printf("command exited %d — see k9s log for captured output", code)
        }
        return // signal kills (Exited()==false) are already filtered upstream
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: :!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.

Related errors


AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15). Data as JSON: /api/errors/0628efd657a2446a. Report an issue: GitHub.