Skip to content

Commit

Permalink
fix: capture errors for shell commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Nov 2, 2024
1 parent 681f6fd commit 2c0a73e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ func getModules() ([]string, error) {
cmd := exec.Command("go", "list", "-m", "-f", "{{.Dir}}")
var out bytes.Buffer
cmd.Stdout = &out
var stderr bytes.Buffer
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("failed to get modules: %w", err)
return nil, fmt.Errorf("failed to get modules: %s: %w", stderr.String(), err)
}

rawModules := strings.Split(out.String(), "\n")
Expand All @@ -47,9 +49,11 @@ func getChangedFiles() ([]string, error) {
cmd := exec.Command("git", "diff", "--name-only", "HEAD^", "HEAD")
var out bytes.Buffer
cmd.Stdout = &out
var stderr bytes.Buffer
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("failed to get changed files: %w", err)
return nil, fmt.Errorf("failed to get changed files: %s: %w", stderr.String(), err)
}

return strings.Split(out.String(), "\n"), nil
Expand Down Expand Up @@ -77,9 +81,11 @@ func getModuleDependencies(module string) ([]string, error) {
cmd := exec.Command("go", "list", "-m", "all", packagePrefix+module)
var out bytes.Buffer
cmd.Stdout = &out
var stderr bytes.Buffer
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("failed to get dependencies for module %s: %w", module, err)
return nil, fmt.Errorf("failed to get dependencies for module %s: %s: %w", module, stderr.String(), err)
}

lines := strings.Split(out.String(), "\n")
Expand Down

0 comments on commit 2c0a73e

Please sign in to comment.