Skip to content

Commit

Permalink
bubble up the error message from go-getter (#18444)
Browse files Browse the repository at this point in the history
  • Loading branch information
shantanugadgil authored Sep 13, 2023
1 parent 46e72aa commit 12580c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/18444.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
status: go-getter failure reason now shown in `alloc status`
```
5 changes: 3 additions & 2 deletions client/allocrunner/taskrunner/getter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ func (s *Sandbox) runCmd(env *parameters) error {

// start & wait for the subprocess to terminate
if err := cmd.Run(); err != nil {
subproc.Log(output, s.logger.Error)
msg := subproc.Log(output, s.logger.Error)

return &Error{
URL: env.Source,
Err: fmt.Errorf("getter subprocess failed: %v", err),
Err: fmt.Errorf("getter subprocess failed: %v: %v", err, msg),
Recoverable: true,
}
}
Expand Down
6 changes: 5 additions & 1 deletion helper/subproc/subproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"os"
"time"
"strings"
)

const (
Expand Down Expand Up @@ -45,12 +46,15 @@ func Print(format string, args ...any) {
//
// r should be a buffer containing output (typically combined stdin + stdout)
// f should be an HCLogger Print method (e.g. log.Debug)
func Log(r io.Reader, f func(msg string, args ...any)) {
func Log(r io.Reader, f func(msg string, args ...any)) string {
scanner := bufio.NewScanner(r)
lines := ""
for scanner.Scan() {
line := scanner.Text()
lines += line + "\n"
f("sub-process", "OUTPUT", line)
}
return strings.TrimSpace(lines)
}

// Context creates a context setup with the given timeout.
Expand Down

0 comments on commit 12580c3

Please sign in to comment.