start logging received json on decode error
This commit is contained in:
parent
2cacdaf22d
commit
fa2ec38d3e
2 changed files with 27 additions and 1 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
|
@ -355,7 +356,16 @@ func (s *Server) read(conn net.Conn, v interface{}) error {
|
|||
return errors.Err(err)
|
||||
}
|
||||
|
||||
return errors.Err(json.NewDecoder(conn).Decode(v))
|
||||
dec := json.NewDecoder(conn)
|
||||
err = dec.Decode(v)
|
||||
if err != nil {
|
||||
data, _ := ioutil.ReadAll(dec.Buffered())
|
||||
if len(data) > 0 {
|
||||
return errors.Err("%s. Data: %s", err.Error(), hex.EncodeToString(data))
|
||||
}
|
||||
return errors.Err(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) readRawBlob(conn net.Conn, blobSize int) ([]byte, error) {
|
||||
|
|
|
@ -144,6 +144,22 @@ func TestServer_Timeout(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
//func TestServer_InvalidJSONHandshake(t *testing.T) {
|
||||
// srv, port := startServerOnRandomPort(t)
|
||||
// defer srv.Shutdown()
|
||||
//
|
||||
// c := Client{}
|
||||
// err := c.Connect(":" + strconv.Itoa(port))
|
||||
// if err != nil {
|
||||
// t.Fatal("error connecting client to server", err)
|
||||
// }
|
||||
//
|
||||
// _, err = c.conn.Write([]byte(`{"stuff":4,tf}"`))
|
||||
// if err == nil {
|
||||
// t.Error("expected an error")
|
||||
// }
|
||||
//}
|
||||
|
||||
type mockPartialStore struct {
|
||||
store.MemoryBlobStore
|
||||
missing []string
|
||||
|
|
Loading…
Reference in a new issue