diff --git a/reflector/server.go b/reflector/server.go index 4584b63..c54b2ad 100644 --- a/reflector/server.go +++ b/reflector/server.go @@ -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) { diff --git a/reflector/server_test.go b/reflector/server_test.go index 878b750..cdcb1ec 100644 --- a/reflector/server_test.go +++ b/reflector/server_test.go @@ -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