Skip to content

Commit 9e6add3

Browse files
author
Matthew Fisher
committed
Merge pull request #3137 from aledbf/fix_builder_messages
fix(builder): return error message as string
2 parents f7b05c7 + 41053f5 commit 9e6add3

4 files changed

Lines changed: 23 additions & 26 deletions

File tree

builder/bin/get-app-config.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"flag"
77
"fmt"
8+
"io/ioutil"
89
"net/http"
910
"os"
1011

@@ -85,15 +86,22 @@ func main() {
8586
os.Exit(1)
8687
}
8788

89+
body, err := ioutil.ReadAll(res.Body)
90+
if err != nil {
91+
fmt.Println(err)
92+
os.Exit(1)
93+
}
94+
8895
if err != nil || res.StatusCode != 200 {
8996
fmt.Println("failed retrieving config from controller")
90-
fmt.Println(res.Body)
97+
fmt.Printf("%v\n", body)
9198
os.Exit(1)
9299
}
93100

94-
config, err := builder.ParseConfig(res)
101+
config, err := builder.ParseConfig(body)
95102
if err != nil {
96103
fmt.Println("failed parsing config from controller")
104+
fmt.Printf("%v\n", err)
97105
os.Exit(1)
98106
}
99107
toString, err := json.Marshal(config)

builder/bin/publish-release-controller.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,20 @@ func main() {
8282
log.Fatalln(err)
8383
}
8484

85-
if res.StatusCode == 503 {
86-
log.Fatalln("check the controller. is it running?")
87-
} else if res.StatusCode != 200 {
88-
log.Fatalf("failed retrieving config from controller: %s\n", res.Body)
89-
}
90-
9185
defer res.Body.Close()
92-
// Read json response from body
86+
9387
body, err := ioutil.ReadAll(res.Body)
9488
if err != nil {
9589
fmt.Println(err)
9690
os.Exit(1)
9791
}
92+
93+
if res.StatusCode == 503 {
94+
log.Fatalln("check the controller. is it running?")
95+
} else if res.StatusCode != 200 {
96+
log.Fatalf("failed retrieving config from controller: %s\n", body)
97+
}
98+
9899
var response map[string]interface{}
99100
if err := json.Unmarshal(body, &response); err != nil {
100101
fmt.Println("invalid controller json response")

builder/utils.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package builder
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
7-
"net/http"
86

97
"gopkg.in/yaml.v2"
108
)
@@ -27,15 +25,9 @@ func YamlToJSON(bytes []byte) (string, error) {
2725
}
2826

2927
// ParseConfig takes a response body from the controller and returns a Config object.
30-
func ParseConfig(res *http.Response) (*Config, error) {
31-
body, err := ioutil.ReadAll(res.Body)
32-
33-
if err != nil {
34-
return nil, err
35-
}
36-
28+
func ParseConfig(body []byte) (*Config, error) {
3729
var config Config
38-
err = json.Unmarshal(body, &config)
30+
err := json.Unmarshal(body, &config)
3931
return &config, err
4032
}
4133

builder/utils_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package builder
33
import (
44
"bytes"
55
"encoding/json"
6-
"net/http"
76
"strings"
87
"testing"
98
"time"
@@ -58,20 +57,17 @@ worker: while true; do echo hello; sleep 1; done`),
5857

5958
func TestParseConfigGood(t *testing.T) {
6059
// mock the controller response
61-
resp := &http.Response{
62-
Body: &ClosingBuffer{bytes.NewBufferString(`{"owner": "test",
60+
resp := bytes.NewBufferString(`{"owner": "test",
6361
"app": "example-go",
6462
"values": {"FOO": "bar", "CAR": 1234},
6563
"memory": {},
6664
"cpu": {},
6765
"tags": {},
6866
"created": "2014-01-01T00:00:00UTC",
6967
"updated": "2014-01-01T00:00:00UTC",
70-
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"}`),
71-
},
72-
}
68+
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"}`)
7369

74-
config, err := ParseConfig(resp)
70+
config, err := ParseConfig(resp.Bytes())
7571

7672
if err != nil {
7773
t.Error(err)

0 commit comments

Comments
 (0)