Skip to content

Commit

Permalink
Removed noisy test output, fixed bad log format, and added error chec…
Browse files Browse the repository at this point in the history
…king for port unmarshaling.
  • Loading branch information
cquinn committed Jun 18, 2014
1 parent 53581bd commit 6ad71c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
12 changes: 10 additions & 2 deletions marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,21 @@ func (i *Instance) UnmarshalJSON(b []byte) error {
if err = json.Unmarshal(b, &ii); err == nil {
marshalLog.Debug("Instance.UnmarshalJSON ii:%+v\n", ii)
*i = Instance(ii)
i.Port, _ = strconv.Atoi(ii.PortJ.Number)
i.SecurePort, _ = strconv.Atoi(ii.SecurePortJ.Number)
i.Port = parsePort(ii.PortJ.Number)
i.SecurePort = parsePort(ii.SecurePortJ.Number)
return nil
}
return err
}

func parsePort(s string) int {
n, err := strconv.Atoi(s)
if err != nil {
log.Warning("Invalid port error: %s", err.Error())
}
return n
}

// UnmarshalJSON is a custom JSON unmarshaler for InstanceMetadata to handle squirreling away
// the raw JSON for later parsing.
func (i *InstanceMetadata) UnmarshalJSON(b []byte) error {
Expand Down
2 changes: 1 addition & 1 deletion net.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (e EurekaConnection) AddMetadataString(ins *Instance, key, value string) er
log.Debug("Updating instance metadata url=%s metadata=%s", reqURL, params)
body, rcode, err := putKV(reqURL, params)
if err != nil {
log.Error("Could not complete update, error: ", err.Error())
log.Error("Could not complete update, error: %s", err.Error())
return err
}
if rcode < 200 || rcode >= 300 {
Expand Down
16 changes: 8 additions & 8 deletions tests/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ func TestJsonMarshal(t *testing.T) {
var v fargo.GetAppsResponseJson
err = json.Unmarshal(blob, &v)

// Handy dump for debugging funky JSON
fmt.Printf("v:\n%+v\n", v.Response.Applications)
for _, app := range v.Response.Applications {
fmt.Printf(" %+v\n", *app)
for _, ins := range app.Instances {
fmt.Printf(" %+v\n", *ins)
if err != nil {
// Handy dump for debugging funky JSON
fmt.Printf("v:\n%+v\n", v.Response.Applications)
for _, app := range v.Response.Applications {
fmt.Printf(" %+v\n", *app)
for _, ins := range app.Instances {
fmt.Printf(" %+v\n", *ins)
}
}
}

if err != nil {
// Print a little more details when there are unmarshalling problems
switch ute := err.(type) {
case *json.UnmarshalTypeError:
Expand Down

0 comments on commit 6ad71c1

Please sign in to comment.