Skip to content

Commit 6c15ebf

Browse files
committed
pkg/compose: build: use jsonmessage.DisplayStream
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 4774cbf commit 6c15ebf

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

pkg/compose/build_classic.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,24 +268,22 @@ func (s *composeService) doBuildImage(ctx context.Context, project *types.Projec
268268
defer response.Body.Close() //nolint:errcheck
269269

270270
imageID := ""
271-
aux := func(msg jsonstream.Message) {
271+
err = jsonmessage.DisplayStream(response.Body, buildBuff, jsonmessage.WithAuxCallback(func(msg jsonstream.Message) {
272272
var result buildtypes.Result
273273
if err := json.Unmarshal(*msg.Aux, &result); err != nil {
274274
logrus.Errorf("Failed to parse aux message: %s", err)
275275
} else {
276276
imageID = result.ID
277277
}
278-
}
279-
280-
err = jsonmessage.DisplayJSONMessagesStream(response.Body, buildBuff, progBuff.FD(), true, aux)
278+
}))
281279
if err != nil {
282280
var jerr *jsonstream.Error
283281
if errors.As(err, &jerr) {
284282
// If no error code is set, default to 1
285-
if jerr.Code == 0 {
286-
jerr.Code = 1
287-
}
288-
return "", cli.StatusError{Status: jerr.Message, StatusCode: jerr.Code}
283+
//
284+
// TODO(thaJeztah): DisplayStream should return a errdefs Error corresponding with the status-code.
285+
errCode := min(1, jerr.Code)
286+
return "", cli.StatusError{Status: jerr.Message, StatusCode: errCode}
289287
}
290288
return "", err
291289
}

0 commit comments

Comments
 (0)