Skip to content

fix(plugin): capture stderr during invocation#32207

Open
c0m1c5an5 wants to merge 2 commits into
helm:mainfrom
c0m1c5an5:main
Open

fix(plugin): capture stderr during invocation#32207
c0m1c5an5 wants to merge 2 commits into
helm:mainfrom
c0m1c5an5:main

Conversation

@c0m1c5an5

Copy link
Copy Markdown

Capture process stderr in plugin invocations via executeCmd.

Closes #31843

What this PR does / why we need it:

Currently, there is an issue with all types of plugins not displaying the stderr on fail, which is the main way the user is
supposed to find out the reason for the failure. This PR fixes the stderr capture for both buffer and fd backed stderr
targets.

Special notes for your reviewer:

InvokeExecError structure has been changed to include stderr.

If applicable:

  • this PR contains user facing changes (the docs needed label should be applied if so)
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

Capture process stderr in plugin invocations via executeCmd.

Closes helm#31843

Signed-off-by: Maksym Kondratenko <[email protected]>
Copilot AI review requested due to automatic review settings June 11, 2026 18:50
@pull-request-size pull-request-size Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR improves plugin error reporting by capturing subprocess stderr and including it in InvokeExecError, then bubbling that richer error up to the CLI.

Changes:

  • Capture and store subprocess stderr in executeCmd and include it in InvokeExecError.
  • Enhance InvokeExecError.Error() to append quoted stderr when present.
  • Add tests to validate stderr capture and “teeing” behavior when an existing cmd.Stderr is provided.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
pkg/cmd/load_plugins.go Returns the enriched InvokeExecError to callers so stderr context is preserved.
internal/plugin/runtime_subprocess.go Implements stderr buffering/teeing and passes captured stderr into InvokeExecError.
internal/plugin/error.go Extends error type to hold stderr and renders it in the error string.
internal/plugin/runtime_subprocess_test.go Adds tests for stderr capture and tee behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +90 to +92
func TestExecuteCmdCapturesStderr(t *testing.T) {
cmd := exec.Command("sh", "-c", `echo "plugin error" >&2; exit 1`)
err := executeCmd(cmd, "test-plugin")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in cb8aa47

Comment on lines 179 to +180
if eerr, ok := err.(*exec.ExitError); ok {
stderr := bytes.TrimSpace(stderrBuf.Bytes())

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The size is usually identical, rarely a bit smaller. Furthermore, this function is not used frequently, so the optimization would not provide much savings, but increase complexity.

Comment thread internal/plugin/error.go
Comment on lines +31 to +33
if len(e.Stderr) > 0 {
return e.Err.Error() + ": " + strconv.Quote(string(e.Stderr))
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I would leave this up to maintainers to decide. Me personally - I would be frustrated if the stderr from a failed plugin would be truncated.

Replace the sh call in plugin stderr capture tests with go native binary
for cross platform test compatibility.

Signed-off-by: Maksym Kondratenko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Helm v4] Logging output from a Python post-renderer subprocess plugin is not visible

2 participants