Skip to content

Commit 83e9f7c

Browse files
authored
gitops: add more context to Run errors (#119)
Co-authored-by: Becojo <[email protected]>
1 parent 88cf5fd commit 83e9f7c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

providers/gitops/gitops.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gitops
33
import (
44
"bytes"
55
"context"
6+
"fmt"
67
"github.com/rs/zerolog/log"
78
"os"
89
"os/exec"
@@ -40,7 +41,14 @@ type ExecGitCommand struct{}
4041
func (g *ExecGitCommand) Run(ctx context.Context, cmd string, args []string, dir string) ([]byte, error) {
4142
command := exec.CommandContext(ctx, cmd, args...)
4243
command.Dir = dir
43-
return command.CombinedOutput()
44+
stdout, err := command.Output()
45+
if err != nil {
46+
if exitErr, ok := err.(*exec.ExitError); ok {
47+
return nil, fmt.Errorf("command `%s` returned an error: %w stderr: %s", command.String(), err, string(exitErr.Stderr))
48+
}
49+
return nil, fmt.Errorf("error running command: %w", err)
50+
}
51+
return stdout, nil
4452
}
4553

4654
func (g *ExecGitCommand) ReadFile(path string) ([]byte, error) {

0 commit comments

Comments
 (0)