Skip to content

feat(cmd): report a failed command's exit status - #518

Merged
kke merged 2 commits into
mainfrom
feat/process-exit-code
Nov 12, 2026
Merged

kke merged 2 commits into
mainfrom
feat/process-exit-code

Conversation

@kke

@kke kke commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Adds ProcessError.ExitCode() and cmd.ExitCodeOf(err), returning -1 when no status was reported.

Since #433, commands run under /bin/sh, so a missing command reads sh: 1: k0s: not found on dash where bash says command not found. k0smotron's RemoteMachine cleanup matched the bash wording and stopped working on Debian and Ubuntu hosts. The exit status (127) is the same under both shells, so it is the reliable thing to check.

  • ssh: x/crypto/ssh.ExitError.ExitStatus()
  • localhost / openssh: exec.ExitError.ExitCode() (over openssh, 255 can also mean the ssh client failed)
  • winrm: the non-zero exit error is now a type with ExitCode(); errors.Is(err, errExitCode) still holds

Additive API, so this would go out as v2.4.0.

Add ProcessError.ExitCode and cmd.ExitCodeOf, read from the error each
protocol's Wait returns: x/crypto/ssh's ExitError, os/exec's ExitError, and
a new winrm error type carrying the code. -1 means no status was reported.

Since commands run under /bin/sh, a shell's wording for a missing command
depends on which shell that is: dash prints "k0s: not found" where bash
prints "command not found". The status (127) is the same on both, so it is
what callers should test instead of matching stderr.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@github-actions github-actions Bot added the additive-change Applied by the API diff workflow label Nov 12, 2026
@github-actions

Copy link
Copy Markdown

Exported API changed by this pull request

Compared against 36f7460.

This only adds exported API.

Compared for linux, windows, darwin. Entries read ./package.Symbol; the module root package is unprefixed.

Compatible changes (2):

- ./cmd.(*ProcessError).ExitCode: added
- ./cmd.ExitCodeOf: added

@kke
kke requested a balanced review from Copilot November 12, 2026 11:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

SSH signal-only termination incorrectly returns a synthesized exit code such as 143 instead of the documented -1, requiring a signal check and regression test.

1 open issue
What changed in this PR

Adds exit-status reporting to command errors so callers can detect failures such as missing commands without relying on shell-specific error messages.

Changes:

  • Adds ProcessError.ExitCode() and cmd.ExitCodeOf(err).
  • Preserves WinRM exit codes in a typed error while retaining sentinel matching.
  • Adds status-reporting tests for command errors, localhost, SSH, and WinRM.
File Description
protocol/​winrm/​connection.go Exposes nonzero exit codes through a typed error.
protocol/​winrm/​connection_test.go Checks that command errors carry the exit code.
protocol/​ssh/​session_test.go Tests propagation of SSH exit status 127.
cmd/​processerror.go Adds public exit-code accessors and protocol error extraction.
cmd/​processerror_test.go Covers status extraction, unavailable statuses, and localhost failures.

Review effort: Balanced

Comment thread cmd/processerror.go Resolved
x/crypto/ssh makes up a status of 128 plus the signal number when the server sends exit-signal without exit-status, so check Signal before trusting ExitStatus, matching os/exec's -1 for a signalled process.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@kke
kke requested a balanced review from Copilot November 12, 2026 12:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the exit-status reporting changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@kke
kke merged commit f70efba into main Nov 12, 2026
18 checks passed
@kke
kke deleted the feat/process-exit-code branch November 12, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

additive-change Applied by the API diff workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants