You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2014/10/13 21:35:53 UTC

git commit: THRIFT-2785 Wrap errors in iostream_transport.go Client: Go Patch: GitHub user cvlchinet

Repository: thrift
Updated Branches:
  refs/heads/master d8dd7ea99 -> 157691fa9


THRIFT-2785 Wrap errors in iostream_transport.go
Client: Go
Patch: GitHub user cvlchinet <cv...@chinet.info>

This closes #246

Wrap errors in iostream_transport.go using NewTTransportExceptionFromError

When I used the StreamTransport to do unit tests I noticed that the EOF TTransportException is not correctly thrown. I quickly found out that the errors in iostream_transport.go where not wrapped with NewTTransportExceptionFromError.


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/157691fa
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/157691fa
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/157691fa

Branch: refs/heads/master
Commit: 157691fa987c6f672585854839598216c08eec44
Parents: d8dd7ea
Author: Jens Geyer <je...@apache.org>
Authored: Mon Oct 13 21:17:55 2014 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Mon Oct 13 21:34:51 2014 +0200

----------------------------------------------------------------------
 lib/go/thrift/iostream_transport.go | 45 +++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/157691fa/lib/go/thrift/iostream_transport.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/iostream_transport.go b/lib/go/thrift/iostream_transport.go
index 17fc969..314eaa6 100644
--- a/lib/go/thrift/iostream_transport.go
+++ b/lib/go/thrift/iostream_transport.go
@@ -149,26 +149,57 @@ func (p *StreamTransport) Flush() error {
 	return nil
 }
 
+func (p *StreamTransport) Read(c []byte) (n int, err error) {
+	n, err = p.Reader.Read(c)
+	if err != nil {
+		err = NewTTransportExceptionFromError(err)
+	}
+	return
+}
+
 func (p *StreamTransport) ReadByte() (c byte, err error) {
 	f, ok := p.Reader.(io.ByteReader)
 	if ok {
-		return f.ReadByte()
+		c, err = f.ReadByte()
+	} else {
+		c, err = readByte(p.Reader)
 	}
-	return readByte(p.Reader)
+	if err != nil {
+		err = NewTTransportExceptionFromError(err)
+	}
+	return
 }
 
-func (p *StreamTransport) WriteByte(c byte) error {
+func (p *StreamTransport) Write(c []byte) (n int, err error) {
+	n, err = p.Writer.Write(c)
+	if err != nil {
+		err = NewTTransportExceptionFromError(err)
+	}
+	return
+}
+
+func (p *StreamTransport) WriteByte(c byte) (err error) {
 	f, ok := p.Writer.(io.ByteWriter)
 	if ok {
-		return f.WriteByte(c)
+		err = f.WriteByte(c)
+	} else {
+		err = writeByte(p.Writer, c)
 	}
-	return writeByte(p.Writer, c)
+	if err != nil {
+		err = NewTTransportExceptionFromError(err)
+	}
+	return
 }
 
 func (p *StreamTransport) WriteString(s string) (n int, err error) {
 	f, ok := p.Writer.(stringWriter)
 	if ok {
-		return f.WriteString(s)
+		n, err = f.WriteString(s)
+	} else {
+		n, err = p.Writer.Write([]byte(s))
+	}
+	if err != nil {
+		err = NewTTransportExceptionFromError(err)
 	}
-	return p.Writer.Write([]byte(s))
+	return
 }