Skip to content

fix: include captured stderr in the failed command message - #166

Open
sarankumar1325 wants to merge 1 commit into
crossplane-contrib:mainfrom
sarankumar1325:fix/failure-message-stderr
Open

sarankumar1325 wants to merge 1 commit into
crossplane-contrib:mainfrom
sarankumar1325:fix/failure-message-stderr

Conversation

@sarankumar1325

Copy link
Copy Markdown

Description of your changes

Fixes #143

When a shellCommand exits non-zero, the fatal result reads shellCmd "..." for "..." failed with : exit status N, with nothing after "failed with". The message is built from exec.ExitError.Stderr, but Go only fills that in from Cmd.Output when Cmd.Stderr is unset. RunFunction sets cmd.Stderr and calls cmd.Run(), so the field is always nil.

This PR builds the message from serr instead. That is the stderr the function already captured and writes to stderrField. With echo 'error output' >&2; exit 1, the result is now ... failed with error output: exit status 1.

This covers only the message part of the issue. The question of whether a non-zero exit should stay Fatal (which drops the desired XR, so stderrField never lands) is a design decision for maintainers and is left unchanged.

TestRunFunction ignores Result.message (protocmp.IgnoreFields), so its expected messages aren't checked. I added TestRunFunctionFailureMessage, which asserts the full message for a failing command with stderr and one without. It fails on main and passes with the fix.

I have:

Tested with go test ./..., go vet ./... and golangci-lint run (v2.14.0, 0 issues).

This change was prepared with help from an AI coding assistant. I reviewed it.

exec.ExitError.Stderr is only filled in by Cmd.Output when Cmd.Stderr
is unset. RunFunction sets Cmd.Stderr and calls Run, so the field was
always nil and the fatal result read "failed with : exit status N".
Use the stderr the function already captured instead.

Fixes crossplane-contrib#143

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell command failures report an empty reason: exiterr.Stderr is always nil

1 participant