From 9a74d1dcfc605e28c9a18525668cbe120e3a53b6 Mon Sep 17 00:00:00 2001 From: Becojo Date: Tue, 4 Jun 2024 14:33:57 -0400 Subject: [PATCH] gitops: add more context to Run errors --- providers/gitops/gitops.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/providers/gitops/gitops.go b/providers/gitops/gitops.go index faf12297..921ae128 100644 --- a/providers/gitops/gitops.go +++ b/providers/gitops/gitops.go @@ -3,6 +3,7 @@ package gitops import ( "bytes" "context" + "fmt" "github.com/rs/zerolog/log" "os" "os/exec" @@ -40,7 +41,14 @@ type ExecGitCommand struct{} func (g *ExecGitCommand) Run(ctx context.Context, cmd string, args []string, dir string) ([]byte, error) { command := exec.CommandContext(ctx, cmd, args...) command.Dir = dir - return command.CombinedOutput() + stdout, err := command.Output() + if err != nil { + if exitErr, ok := err.(*exec.ExitError); ok { + return nil, fmt.Errorf("command `%s` returned an error: %w stderr: %s", command.String(), err, string(exitErr.Stderr)) + } + return nil, fmt.Errorf("error running command: %w", err) + } + return stdout, nil } func (g *ExecGitCommand) ReadFile(path string) ([]byte, error) {