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

Commit

Permalink
Increase logging visibility for builder errors
Browse files Browse the repository at this point in the history
Signed-off-by: tylerslaton <mtslaton1@gmail.com>
  • Loading branch information
tylerslaton committed Jul 14, 2023
1 parent 6a27de7 commit e448c26
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/buildclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package buildclient
import (
"context"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -31,11 +32,24 @@ type WebSocketDialer func(ctx context.Context, urlStr string, requestHeader http

func Stream(ctx context.Context, cwd string, streams *streams.Output, dialer WebSocketDialer,
creds CredentialLookup, build *apiv1.AcornImageBuild) (*v1.AppImage, error) {
conn, _, err := dialer(ctx, wsURL(build.Status.BuildURL), map[string][]string{
conn, response, err := dialer(ctx, wsURL(build.Status.BuildURL), map[string][]string{
"X-Acorn-Build-Token": {build.Status.Token},
})
if response.Body != nil {
defer response.Body.Close()
}
if err != nil {
return nil, err
if response.Body == nil {
return nil, err
}

// If there was a body and an error ocurred, read the body and write it
// into the error message.
body, readErr := io.ReadAll(response.Body)
if readErr != nil {
return nil, fmt.Errorf("%w: status %v, error occured while reading builder response body: %v", err, response.StatusCode, readErr)
}
return nil, fmt.Errorf("%w: %v, %v", err, response.StatusCode, string(body))
}

var (
Expand Down

0 comments on commit e448c26

Please sign in to comment.