Skip to content

Commit f14c15f

Browse files
ndeloofglours
authored andcommitted
capture error message reported by bake and forward to compose
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent 8d68ef5 commit f14c15f

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

pkg/compose/build_bake.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
package compose
1818

1919
import (
20+
"bufio"
2021
"bytes"
2122
"context"
2223
"encoding/json"
2324
"errors"
2425
"fmt"
25-
"io"
2626
"os"
2727
"os/exec"
2828
"path/filepath"
@@ -272,18 +272,23 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
272272
return nil, err
273273
}
274274

275+
var errMessage string
276+
scanner := bufio.NewScanner(pipe)
277+
scanner.Split(bufio.ScanLines)
278+
275279
err = cmd.Start()
276280
if err != nil {
277281
return nil, err
278282
}
279283
eg.Go(cmd.Wait)
280-
for {
281-
decoder := json.NewDecoder(pipe)
284+
for scanner.Scan() {
285+
line := scanner.Text()
286+
decoder := json.NewDecoder(strings.NewReader(line))
282287
var status client.SolveStatus
283288
err := decoder.Decode(&status)
284289
if err != nil {
285-
if errors.Is(err, io.EOF) {
286-
break
290+
if strings.HasPrefix(line, "ERROR: ") {
291+
errMessage = line[7:]
287292
}
288293
continue
289294
}
@@ -293,7 +298,10 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
293298

294299
err = eg.Wait()
295300
if err != nil {
296-
return nil, err
301+
if errMessage != "" {
302+
return nil, errors.New(errMessage)
303+
}
304+
return nil, fmt.Errorf("failed to execute bake: %w", err)
297305
}
298306

299307
b, err = os.ReadFile(metadata.Name())

pkg/e2e/build_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ func TestBuildPlatformsStandardErrors(t *testing.T) {
403403
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms", "build")
404404
res.Assert(t, icmd.Expected{
405405
ExitCode: 1,
406-
Err: `Multi-platform build is not supported for the docker driver.
407-
Switch to a different driver, or turn on the containerd image store, and try again.`,
406+
Err: "Multi-platform build is not supported for the docker driver.",
408407
})
409408
})
410409

0 commit comments

Comments
 (0)