From 0f2017e9a72a2be7a11533d53f52185076c5b57e Mon Sep 17 00:00:00 2001 From: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com> Date: Tue, 13 Feb 2024 10:13:49 -0500 Subject: [PATCH] Include plugin `stderr` with wrapped error This allows plugins to provide more details aside from just `exit status 1` inside the error Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com> --- api/internal/plugins/execplugin/execplugin.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/internal/plugins/execplugin/execplugin.go b/api/internal/plugins/execplugin/execplugin.go index 001731f7807..ec82c348d6a 100644 --- a/api/internal/plugins/execplugin/execplugin.go +++ b/api/internal/plugins/execplugin/execplugin.go @@ -169,15 +169,16 @@ func (p *ExecPlugin) invokePlugin(input []byte) ([]byte, error) { p.path, append([]string{f.Name()}, p.args...)...) cmd.Env = p.getEnv() cmd.Stdin = bytes.NewReader(input) - cmd.Stderr = os.Stderr + var stdErr bytes.Buffer + cmd.Stderr = &stdErr if _, err := os.Stat(p.h.Loader().Root()); err == nil { cmd.Dir = p.h.Loader().Root() } result, err := cmd.Output() if err != nil { return nil, errors.WrapPrefixf( - err, "failure in plugin configured via %s; %v", - f.Name(), err.Error()) + fmt.Errorf("failure in plugin configured via %s; %w", + f.Name(), err), stdErr.String()) } return result, os.Remove(f.Name()) }