Repository navigation
fix: include captured stderr in the failed command message - #166
Open
sarankumar1325 wants to merge 1 commit into
Open
sarankumar1325 wants to merge 1 commit into
sarankumar1325 wants to merge 1 commit into
Conversation
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>
sarankumar1325
requested review from
humoflife,
jastang and
stevendborrelli
as code owners
October 30, 2026 05:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of your changes
Fixes #143
When a
shellCommandexits non-zero, the fatal result readsshellCmd "..." for "..." failed with : exit status N, with nothing after "failed with". The message is built fromexec.ExitError.Stderr, but Go only fills that in fromCmd.OutputwhenCmd.Stderris unset.RunFunctionsetscmd.Stderrand callscmd.Run(), so the field is always nil.This PR builds the message from
serrinstead. That is the stderr the function already captured and writes tostderrField. Withecho '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, sostderrFieldnever lands) is a design decision for maintainers and is left unchanged.TestRunFunctionignoresResult.message(protocmp.IgnoreFields), so its expected messages aren't checked. I addedTestRunFunctionFailureMessage, which asserts the full message for a failing command with stderr and one without. It fails onmainand passes with the fix.I have:
contribution process. Also see docs.
Tested with
go test ./...,go vet ./...andgolangci-lint run(v2.14.0, 0 issues).This change was prepared with help from an AI coding assistant. I reviewed it.