From 8be21fb5396624d76dc79af73ca37060e3de9913 Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Sat, 23 Apr 2016 10:59:38 -0700 Subject: [PATCH 1/2] Fix unmarshall error with Invite, improve error logging. --- restapi.go | 8 ++++---- structs.go | 2 +- wsapi.go | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/restapi.go b/restapi.go index 8f8a656..08918d7 100644 --- a/restapi.go +++ b/restapi.go @@ -1108,10 +1108,10 @@ func (s *Session) ChannelInvites(channelID string) (st []*Invite, err error) { func (s *Session) ChannelInviteCreate(channelID string, i Invite) (st *Invite, err error) { data := struct { - MaxAge int `json:"max_age"` - MaxUses int `json:"max_uses"` - Temporary bool `json:"temporary"` - XKCDPass bool `json:"xkcdpass"` + MaxAge int `json:"max_age"` + MaxUses int `json:"max_uses"` + Temporary bool `json:"temporary"` + XKCDPass string `json:"xkcdpass"` }{i.MaxAge, i.MaxUses, i.Temporary, i.XkcdPass} body, err := s.Request("POST", CHANNEL_INVITES(channelID), data) diff --git a/structs.go b/structs.go index 322ad11..2102e9e 100644 --- a/structs.go +++ b/structs.go @@ -107,7 +107,7 @@ type Invite struct { MaxAge int `json:"max_age"` Uses int `json:"uses"` MaxUses int `json:"max_uses"` - XkcdPass bool `json:"xkcdpass"` + XkcdPass string `json:"xkcdpass"` Revoked bool `json:"revoked"` Temporary bool `json:"temporary"` } diff --git a/wsapi.go b/wsapi.go index 765b705..3d1da3e 100644 --- a/wsapi.go +++ b/wsapi.go @@ -15,6 +15,7 @@ import ( "compress/zlib" "encoding/json" "errors" + "fmt" "io" "log" "net/http" @@ -256,7 +257,7 @@ func (s *Session) event(messageType int, message []byte) { if messageType == 2 { z, err1 := zlib.NewReader(reader) if err1 != nil { - log.Println(err1) + log.Println(fmt.Sprintf("Error uncompressing message type %d: %s", messageType, err1)) return } defer func() { @@ -271,7 +272,7 @@ func (s *Session) event(messageType int, message []byte) { var e *Event decoder := json.NewDecoder(reader) if err = decoder.Decode(&e); err != nil { - log.Println(err) + log.Println(fmt.Sprintf("Error decoding message type %d: %s", messageType, err)) return } @@ -287,7 +288,7 @@ func (s *Session) event(messageType int, message []byte) { // Attempt to unmarshal our event. // If there is an error we should handle the event itself. if err = unmarshal(e.RawData, i); err != nil { - log.Println("Unable to unmarshal event data.", err) + log.Println(fmt.Sprintf("Unable to unmarshal event %s data: %s", e.Type, err)) // Ready events must fire, even if they are empty. if e.Type != "READY" { i = nil From bf9dda84049a5894bb2f392e8ad200a2b1342e42 Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Sat, 23 Apr 2016 11:58:19 -0700 Subject: [PATCH 2/2] Use json.Unmarshal in event handling so errors are better. --- wsapi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsapi.go b/wsapi.go index 3d1da3e..bf060ba 100644 --- a/wsapi.go +++ b/wsapi.go @@ -287,7 +287,7 @@ func (s *Session) event(messageType int, message []byte) { // Attempt to unmarshal our event. // If there is an error we should handle the event itself. - if err = unmarshal(e.RawData, i); err != nil { + if err = json.Unmarshal(e.RawData, i); err != nil { log.Println(fmt.Sprintf("Unable to unmarshal event %s data: %s", e.Type, err)) // Ready events must fire, even if they are empty. if e.Type != "READY" {