Repository: thrift Updated Branches: refs/heads/master d8dd7ea99 -> 157691fa9
THRIFT-2785 Wrap errors in iostream_transport.go Client: Go Patch: GitHub user cvlchinet <[email protected]> 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 <[email protected]> Authored: Mon Oct 13 21:17:55 2014 +0200 Committer: Jens Geyer <[email protected]> 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 }
