Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit e448c26

Browse files
committed
Increase logging visibility for builder errors
Signed-off-by: tylerslaton <mtslaton1@gmail.com>
1 parent 6a27de7 commit e448c26

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pkg/buildclient/client.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package buildclient
33
import (
44
"context"
55
"fmt"
6+
"io"
67
"net/http"
78
"os"
89
"path/filepath"
@@ -31,11 +32,24 @@ type WebSocketDialer func(ctx context.Context, urlStr string, requestHeader http
3132

3233
func Stream(ctx context.Context, cwd string, streams *streams.Output, dialer WebSocketDialer,
3334
creds CredentialLookup, build *apiv1.AcornImageBuild) (*v1.AppImage, error) {
34-
conn, _, err := dialer(ctx, wsURL(build.Status.BuildURL), map[string][]string{
35+
conn, response, err := dialer(ctx, wsURL(build.Status.BuildURL), map[string][]string{
3536
"X-Acorn-Build-Token": {build.Status.Token},
3637
})
38+
if response.Body != nil {
39+
defer response.Body.Close()
40+
}
3741
if err != nil {
38-
return nil, err
42+
if response.Body == nil {
43+
return nil, err
44+
}
45+
46+
// If there was a body and an error ocurred, read the body and write it
47+
// into the error message.
48+
body, readErr := io.ReadAll(response.Body)
49+
if readErr != nil {
50+
return nil, fmt.Errorf("%w: status %v, error occured while reading builder response body: %v", err, response.StatusCode, readErr)
51+
}
52+
return nil, fmt.Errorf("%w: %v, %v", err, response.StatusCode, string(body))
3953
}
4054

4155
var (

0 commit comments

Comments
 (0)