Skip to content

Commit 573bb30

Browse files
optimus-fulcriaclaudeinFocus7
authored
fix: include docker stderr in error messages (#278)
<!-- Thanks for opening a PR! Please delete any sections that don't apply. --> # Description <!-- - **Motivation:** why this change is needed - **What changed:** key implementation details - **Related issues:** e.g., `Fixes #123` --> When Docker commands fail, only stdout was captured, making it difficult to diagnose build and deployment failures. Docker typically writes error details to stderr. The `Executor.Run` method in `docker.go` now uses `io.MultiWriter(os.Stderr, &stderrBuf)` to both display stderr in real time and capture it for inclusion in the returned error message when the command fails. To reduce log pollution, outputs are now backed by `--verbose` flag. Following a similar approach to the agentregistry-runtime, we print to both stderr + buffer error when verbose is enabled, else we simply output the buffer-captured error with the returned error message. Fixes #193 ## Validation ```sh # init a skill go run cmd/cli/main.go skill init test ``` Non-verbose output would only log the captured docker error ```sh # invalid build without verbose logging go run cmd/cli/main.go skill build test --image 'invalid!!tag' ``` ```output Building skill "hello-world-template" as Docker image: invalid!!tag Error: build failed for skill "hello-world-template": docker build failed: exit status 1 ERROR: failed to build: invalid tag "invalid!!tag": invalid reference format exit status 1 ``` Verbose output will log std logs, the stderr, and final captured docker error (which technically leads to duplicated from stderr + captured err returned) ```sh # invalid skill with verbose logging go run cmd/cli/main.go skill build test --image 'invalid!!tag' --verbose ``` ```output Building skill "hello-world-template" as Docker image: invalid!!tag Running: docker build -t invalid!!tag -f /var/folders/zy/pkk0_2ys5yx8y1syxw5xjxhh0000gn/T/skill-dockerfile-654053150 /Users/fabiangonz98/go/src/github.com/solo-io/agentregistry/test Working directory: /Users/fabiangonz98/go/src/github.com/solo-io/agentregistry/test ERROR: failed to build: invalid tag "invalid!!tag": invalid reference format Error: build failed for skill "hello-world-template": docker build failed: exit status 1 ERROR: failed to build: invalid tag "invalid!!tag": invalid reference format exit status 1 ``` # Change Type ``` /kind fix ``` # Changelog <!-- Provide the exact line to appear in release notes for the chosen changelog type. If no, just write "NONE" in the release-note block below. If yes, a release note is required: --> ```release-note Include docker stderr in error messages for better debugging ``` # Additional Notes <!-- Any extra context or edge cases for reviewers. --> --------- Signed-off-by: Fabian Gonzalez <fabian.gonzalez@solo.io> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Fabian Gonzalez <fabian.gonzalez@solo.io>
1 parent eec7764 commit 573bb30

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

internal/cli/common/docker/docker.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package docker
22

33
import (
4+
"bytes"
45
"fmt"
6+
"io"
57
"os"
68
"os/exec"
79
"strings"
@@ -37,6 +39,8 @@ func (e *Executor) CheckAvailability() error {
3739
}
3840

3941
// Run executes docker with the provided arguments.
42+
// When Verbose is true, stdout and stderr are streamed to the terminal.
43+
// When Verbose is false, only the stderr is captured and is included in the returned error message.
4044
func (e *Executor) Run(args ...string) error {
4145
if e.Verbose {
4246
printer.PrintInfo(fmt.Sprintf("Running: docker %s", strings.Join(args, " ")))
@@ -46,12 +50,22 @@ func (e *Executor) Run(args ...string) error {
4650
}
4751

4852
cmd := exec.Command("docker", args...)
49-
cmd.Stdout = os.Stdout
50-
cmd.Stderr = os.Stderr
5153
if e.WorkDir != "" {
5254
cmd.Dir = e.WorkDir
5355
}
54-
return cmd.Run()
56+
57+
var stderrBuf bytes.Buffer
58+
if e.Verbose {
59+
cmd.Stdout = os.Stdout
60+
cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)
61+
} else {
62+
cmd.Stderr = &stderrBuf
63+
}
64+
65+
if err := cmd.Run(); err != nil {
66+
return fmt.Errorf("%w\n%s", err, strings.TrimSpace(stderrBuf.String()))
67+
}
68+
return nil
5569
}
5670

5771
// Build runs docker build with the supplied tag, context, and additional args.

0 commit comments

Comments
 (0)